【问题标题】:Htaccess redirect Laravel 4Htaccess 重定向 Laravel 4
【发布时间】:2013-11-19 04:13:39
【问题描述】:

我安装了 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>
Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

样板规则

<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

【问题讨论】:

    标签: regex .htaccess mod-rewrite redirect laravel-4


    【解决方案1】:

    更改规则的顺序:

    <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>
    

    一般来说,将 301 规则放在内部重写规则之前。

    【讨论】:

      猜你喜欢
      • 2015-09-02
      • 2020-05-15
      • 2015-03-28
      • 2018-05-27
      • 2014-11-18
      • 2013-09-03
      • 2013-12-25
      • 2013-05-30
      • 2018-05-06
      相关资源
      最近更新 更多