【问题标题】:FastCGI .htaccess redirect not workingFastCGI .htaccess 重定向不起作用
【发布时间】:2015-08-03 17:01:18
【问题描述】:

我正在使用 fastcgi 的服务器上开发 PHP、MVC、Web 应用程序。由于 fastCGI,我不得不像这样在我的 RewriteRule 中使用问号:

RewriteRule ^(.*)$ index.php?/$1 [L] 

但是当我尝试做一个简单的 301 重定向时,我最终被重定向到一个尴尬的网址,如下所示:http://example.com/bg/home/login?/admin

我的 .htaccess 看起来像这样:

RewriteEngine On
DirectoryIndex index.php

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Redirect 301 /admin /bg/home/login

关于如何正确执行 301 重定向的任何想法?

【问题讨论】:

    标签: php .htaccess redirect fastcgi


    【解决方案1】:

    你应该在最后一个 RewriteCond 之后为这个 URI 添加一个例外:

    RewriteCond %{REQUEST_URI} !^/bg/home/login$
    

    如果你想摆脱查询字符串,更好的方法是使用 RewriteRule 而不是 Redirect。在第一个 RewriteCond 之前添加:

    RewriteRule ^admin$ /bg/home/login? [R=301,L]
    

    【讨论】:

      猜你喜欢
      • 2015-03-07
      • 2015-08-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-30
      • 2013-04-06
      • 2017-06-30
      相关资源
      最近更新 更多