问题
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 to this url:
/information/
Redirects me to:
/home/xxx/Dropbox/Development/laravel/httpdocs/information
So the trailing slash is being removed, but it redirecting to the abolsute URL.
Why is it doing that? How do I fix it?
Thanks :)
回答1:
Add a RewriteBase /
(or whatever the base URI should be) above all of your rules.
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.
来源:https://stackoverflow.com/questions/14097941/mod-rewrite-remove-trailing-slash-not-working-in-laravel