Htaccess redirect Laravel 4

拜拜、爱过 提交于 2019-12-22 09:04:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!