D
D
Dmitriy2020-02-20 10:43:44
Apache HTTP Server
Dmitriy, 2020-02-20 10:43:44

How to redirect all requests in public Laravel 6, Apache, XAMPP?

You need to redirect all requests from the site root to the public folder.
Standard .htaccess in the public folder (public/.htaccess)

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>


Added .htaccess to root folder
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^public
    RewriteRule (.*) public
</IfModule>

It works, but the path becomes: localhost/myProject/public/
How to remove it to become: localhost/myProject/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sanes, 2020-02-20
@dmitriyuvin

RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule ((?s).*) public/$1 [L]

or
RewriteEngine On
RewriteRule ^(.*)$ public/$1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question