【发布时间】:2015-12-20 09:25:34
【问题描述】:
任务看起来很简单:
所有请求都必须通过一个文件传递。
然而,
当以下代码添加到 httpd.conf 时:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?route=$1 [QSA,R=301,L]
以下代码被添加到/index.php:
if( isset($_GET["route"]) && $_GET["route"] != "/index.php" ){
header("Location: ".$_GET["route"]);
}
然后它会导致重定向循环!
导致例如这样的循环:
www.site.com/image.jpg ->(由 httpd.conf 重定向)
www.site.com/index.php?route=/image.jpg ->(由 index.php 重定向)
www.site.com/image.jpg ->(由 httpd.conf 重定向)
www.site.com/index.php?route=/image.jpg ->(由 index.php 重定向)
...
所以,问题如下:
如何停止这个循环?
例如以这种方式停止:
www.site.com/image.jpg ->(由 httpd.conf 重定向)
www.site.com/index.php?route=/image.jpg ->(由 index.php 重定向)
www.site.com/image.jpg(没有进一步的重定向)
【问题讨论】:
-
您究竟想用这个重写/重定向方案完成什么?这将有助于找到解决方案。
-
@amarnasan 它写在消息的开头 - 所有请求都必须通过一个文件传递(在本机处理请求开始之前执行一些额外的操作)
标签: php apache .htaccess mod-rewrite redirect