mod_rewrite的删除斜杠不工作在Laravel [英] mod_rewrite remove trailing slash not working in Laravel
问题描述
我在我的htaccess的文件以下code设置为我Laravel 3安装:
I have the following code setup in my htaccess file for my Laravel 3 installation:
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# Enforce www
RewriteCond %{HTTP_HOST} ^([0-9a-z-]+)\.([0-9a-z-]+)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Remove index.php from base URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
这看起来一切都很好,直到被访问的第一个重写条件。
Which looks all well and good untill the first ReWrite condition is accessed.
Navagating到这个网址:
Navagating to this url:
/information/
重定向我:
/home/xxx/Dropbox/Development/laravel/httpdocs/information
所以斜线已经被删除,但它重定向到abolsute网址。
So the trailing slash is being removed, but it redirecting to the abolsute URL.
为什么这样做?如何解决呢?
Why is it doing that? How do I fix it?
感谢:)
推荐答案
添加的RewriteBase /
(或任何基本URI应该是)上面所有规则。
Add a RewriteBase /
(or whatever the base URI should be) above all of your rules.
这是怎么回事是mod_rewrite的尝试猜测,如果重写规则的目标是一个URL路径或文件路径,它是猜测正确,这是一个文件路径,并追加了不正确的基本路径。
What's happening is that mod_rewrite tries to guess if the target of a rewrite rule is a URL path or a file path and it is guessing incorrectly that it's a file path and appends the incorrect base path.
这篇关于mod_rewrite的删除斜杠不工作在Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!