问题
I have a Laravel 4 installation, and I used the boilerplate's htaccess to redirect my site from:
site.com.br
to www.site.com.br
(notice the www).
But when I use a route such as site.com.br/TITLE-OF-MY-POST
I am redirected to:
www.site.com.br/index.php
instead of www.site.com.br/TITLE-OF-MY-POST"
Does anyone know why? Here my htaccess rules:
Laravel's rule
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Boilerplate's rule
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
回答1:
Change order of your rules:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
In general keep your 301 rules before your internal rewrite rules.
来源:https://stackoverflow.com/questions/19837257/htaccess-redirect-laravel-4