简体   繁体   中英

Laravel htaccess redirects in wrong way

Thanks in advance.

I am using laravel 5 and want some fixes in .htaccess file.

Here is my .htaccess file.

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

    RewriteEngine On

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

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

The problem is that when i am adding an extra slash after the url it is throwing me at very root of my www folder. Is there any possible solution

http://localhost/project/public/index.php --works fine. http://localhost/project/public/index.php/ --Redirecting me to http://localhost/index.php

Anyhow i need this redirect to http://localhost/project/public/index.php

Any help appreciated.

Finally got the perfect solution.

RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)/$ /$1 [L,R=301] // i have replaced the '/' and it worked.
RewriteRule ^(.*)/$ $1 [L,R=301]

看一下config/app.php ,将URL指向您的项目文件夹

'url' => 'http://localhost',

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM