laravel 尾部斜杠重定向到本地主机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21735527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
laravel trailing Slashes redirect to localhost
提问by user3213240
When I try this
当我尝试这个时
http://localhost/Testlaravel/public/users/login
it works. But when I try
有用。但是当我尝试
http://localhost/Testlaravel/public/users/login/
it redirects me to
它把我重定向到
http://localhost/users/login/
Any idea why?
知道为什么吗?
This my htaccess file
这是我的 htaccess 文件
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
回答by anubhava
Change your code to this:
将您的代码更改为:
Options -MultiViews
RewriteEngine On
RewriteBase /Testlaravel/public/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
回答by Rana
If the above method not working then clear your browser history with cache and try again.
如果上述方法不起作用,请使用缓存清除浏览器历史记录,然后重试。
回答by Tiago Gouvêa
I Just added this to my .htaccess file and it worked fine!
我刚刚将它添加到我的 .htaccess 文件中,它运行良好!
RewriteCond %{REQUEST_URI} !^
回答by Karthick
My project directory is
我的项目目录是
c:\wamp\www\laravel_apps\li3\
c:\wamp\www\laravel_apps\li3\
and changed the .htaccess inside public folder to the following
并将公用文件夹内的 .htaccess 更改为以下内容
<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 ^(.*)/$ /laravel_apps/li3/public/ [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
i just replaced
我刚换了
RewriteRule ^(.*)/$ / [L,R=301]
to
到
RewriteRule ^(.*)/$ /laravel_apps/li3/public/ [L,R=301]
now, if you put an slash at an end of the url it will redirected to the same page
现在,如果您在 url 的末尾放置一个斜杠,它将重定向到同一页面