【发布时间】:2013-12-09 07:33:37
【问题描述】:
Apache 版本:Apache/2.2.22 (Ubuntu)
我在.htaccess 文件中定义了以下重写规则
RewriteRule ^goto/(.*)$ goto/index.php?q=$1 [L,QSA]
它工作正常(意味着它正在到达 goto 文件夹的 index.php)。但我认为它应该生成一个重定向循环。
假设一个网址是http://example.com/goto/foo。所以在第一次迭代中它将有http://example.com/goto/index.php?q=foo。在第二次迭代中,它应该匹配 rewriterule goto/(.*) 并且应该有一个重定向循环。
我的问题是它如何避免重定向循环?
我的 .htacces 文件只包含以下内容。
RewriteEngine on
RewriteRule ^goto/(.*)$ goto/index.php?q=$1 [L,QSA]
在 goto 文件夹内只有 index.php。那里没有其他文件。
编辑
我还使用 wamp 2.2 对此进行了测试 Apache 2.2.2 版
以下是重写日志
[perdir D:/wamp/www/test/blog/] strip per-dir prefix: D:/wamp/www/test/blog/goto/ddfd -> goto/ddfd
[perdir D:/wamp/www/test/blog/] applying pattern '^goto/(.*)$' to uri 'goto/ddfd'
[perdir D:/wamp/www/test/blog/] rewrite 'goto/ddfd' -> 'goto/index.php?q=ddfd'
split uri=goto/index.php?q=ddfd -> uri=goto/index.php, args=q=ddfd
[perdir D:/wamp/www/test/blog/] add per-dir prefix: goto/index.php -> D:/wamp/www/test/blog/goto/index.php
[perdir D:/wamp/www/test/blog/] strip document_root prefix: D:/wamp/www/test/blog/goto/index.php -> /test/blog/goto/index.php
[perdir D:/wamp/www/test/blog/] internal redirect with /test/blog/goto/index.php [INTERNAL REDIRECT]
[perdir D:/wamp/www/test/blog/] strip per-dir prefix: D:/wamp/www/test/blog/goto/index.php -> goto/index.php
[perdir D:/wamp/www/test/blog/] applying pattern '^goto/(.*)$' to uri 'goto/index.php'
[perdir D:/wamp/www/test/blog/] rewrite 'goto/index.php' -> 'goto/index.php?q=index.php'
split uri=goto/index.php?q=index.php -> uri=goto/index.php, args=q=index.php&q=ddfd
[perdir D:/wamp/www/test/blog/] add per-dir prefix: goto/index.php -> D:/wamp/www/test/blog/goto/index.php
[perdir D:/wamp/www/test/blog/] initial URL equal rewritten URL: D:/wamp/www/test/blog/goto/index.php [IGNORING REWRITE]
最后一个条目说它正在忽略重写。那么在这种情况下,实际上是什么配置指示忽略重写?
【问题讨论】:
-
来自文档,
The [L] flag causes mod_rewrite to stop processing the rule set.doc -
@HussainTamboli 但是
.htaccess中的[L]标志只会停止当前循环。它将返回它当前重写的内容,一遍又一遍地调用.htaccess,直到url停止变化。 -
@chanchal118:我的猜测是你可能有
goto/.htaccess或者当前.htaccess 中的其他一些,它正在重写这个。 -
如果您没有收到错误,请检查您的
httpd.conf文件。 -
@Sumurai8 我的 apache 版本是 Apache/2.2.22 (Ubuntu) 。我应该在 apache2.conf 中寻找哪个配置/指令?
标签: apache .htaccess mod-rewrite