.htaccess的重定向Laravel 4 [英] Htaccess redirect Laravel 4

查看:238
本文介绍了.htaccess的重定向Laravel 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Laravel 4安装,我用了样板的htaccess的重定向我的网站的:

site.com.br www.site.com.br (注意 WWW )。

但是当我使用的路径,例如 site.com.br/TITLE-OF-MY-POST 我重定向到:

www.site.com.br/index.php 而不是 www.site.com.br/TITLE-OF-MY-POST

有谁知道为什么吗?在这里,我的htaccess的规则:

Laravel的规则

 < IfModule mod_rewrite.c>
选项​​-MultiViews
RewriteEngine叙述上

的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^的index.php [L]
< / IfModule>
 

样板的规则

 < IfModule mod_rewrite.c>
的RewriteCond%{} HTTPS!=上
的RewriteCond%{HTTP_HOST}!^ WWW \ .. + $ [NC]
重写规则^ HTTP://www.% {HTTP_HOST}%{REQUEST_URI} [R = 301,L]
< / IfModule>
 

解决方案

您的规则更改为了:

 < IfModule mod_rewrite.c>
选项​​-MultiViews
RewriteEngine叙述上

的RewriteCond%{} HTTPS关闭
的RewriteCond%{HTTP_HOST}!^ WWW \。 [NC]
重写规则^ HTTP://www.% {HTTP_HOST}%{REQUEST_URI} [R = 301,L,NE]

的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^的index.php [L]

< / IfModule>
 

在一般的内部重写规则之前,让你的301规则。

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>

解决方案

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.

这篇关于.htaccess的重定向Laravel 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆