停止mod_rewrite规则匹配,循环执行

时间:2009-09-22 17:39:16

标签: apache mod-rewrite rewrite

我在目录上有old.htm和new.htm,每次有人访问old.htm时我都需要加载file.php,每次访问new.htm时都要加载old.htm。

以下是我的非工作规则:

RewriteRule ^old\.htm$ file.php?%{REQUEST_URI} [L]
RewriteRule ^new\.htm$ old.htm [L]

访问old.htm时,会调用file.php。访问new.htm时,再次“访问”old.htm,将其重写为file.php。所以,最后,访问new.php加载file.php,但我想停在old.htm。

有什么想法吗?

如果有帮助,这里是RewriteLogLevel 3输出:

old.htm

[rid#2006ee0/initial] (3) [per-dir D:/dev/www/estadao/arquivoweb/] strip per-dir prefix: D:/dev/www/estadao/arquivoweb/old.htm -> old.htm
[rid#2006ee0/initial] (3) [per-dir D:/dev/www/estadao/arquivoweb/] applying pattern '^old\.htm$' to uri 'old.htm'
[rid#2006ee0/initial] (2) [per-dir D:/dev/www/estadao/arquivoweb/] rewrite old.htm -> file.php?/arquivoweb/old.htm
[rid#2006ee0/initial] (3) split uri=file.php?/arquivoweb/old.htm -> uri=file.php, args=/arquivoweb/old.htm
[rid#2006ee0/initial] (3) [per-dir D:/dev/www/estadao/arquivoweb/] add per-dir prefix: file.php -> D:/dev/www/estadao/arquivoweb/file.php
[rid#2006ee0/initial] (2) [per-dir D:/dev/www/estadao/arquivoweb/] strip document_root prefix: D:/dev/www/estadao/arquivoweb/file.php -> /arquivoweb/file.php
[rid#2006ee0/initial] (1) [per-dir D:/dev/www/estadao/arquivoweb/] internal redirect with /arquivoweb/file.php [INTERNAL REDIRECT]
[rid#200fb20/initial/redir#1] (3) [per-dir D:/dev/www/estadao/arquivoweb/] strip per-dir prefix: D:/dev/www/estadao/arquivoweb/file.php -> file.php
[rid#200fb20/initial/redir#1] (3) [per-dir D:/dev/www/estadao/arquivoweb/] applying pattern '^old\.htm$' to uri 'file.php'
[rid#200fb20/initial/redir#1] (3) [per-dir D:/dev/www/estadao/arquivoweb/] strip per-dir prefix: D:/dev/www/estadao/arquivoweb/file.php -> file.php
[rid#200fb20/initial/redir#1] (3) [per-dir D:/dev/www/estadao/arquivoweb/] applying pattern '^new\.htm$' to uri 'file.php'
[rid#200fb20/initial/redir#1] (1) [per-dir D:/dev/www/estadao/arquivoweb/] pass through D:/dev/www/estadao/arquivoweb/file.php

new.htm

[rid#2006ee0/initial] (3) [per-dir D:/dev/www/estadao/arquivoweb/] strip per-dir prefix: D:/dev/www/estadao/arquivoweb/new.htm -> new.htm
[rid#2006ee0/initial] (3) [per-dir D:/dev/www/estadao/arquivoweb/] applying pattern '^old\.htm$' to uri 'new.htm'
[rid#2006ee0/initial] (3) [per-dir D:/dev/www/estadao/arquivoweb/] strip per-dir prefix: D:/dev/www/estadao/arquivoweb/new.htm -> new.htm
[rid#2006ee0/initial] (3) [per-dir D:/dev/www/estadao/arquivoweb/] applying pattern '^new\.htm$' to uri 'new.htm'
[rid#2006ee0/initial] (2) [per-dir D:/dev/www/estadao/arquivoweb/] rewrite new.htm -> old.htm
[rid#2006ee0/initial] (3) [per-dir D:/dev/www/estadao/arquivoweb/] add per-dir prefix: old.htm -> D:/dev/www/estadao/arquivoweb/old.htm
[rid#2006ee0/initial] (2) [per-dir D:/dev/www/estadao/arquivoweb/] strip document_root prefix: D:/dev/www/estadao/arquivoweb/old.htm -> /arquivoweb/old.htm
[rid#2006ee0/initial] (1) [per-dir D:/dev/www/estadao/arquivoweb/] internal redirect with /arquivoweb/old.htm [INTERNAL REDIRECT]
[rid#200fa90/initial/redir#1] (3) [per-dir D:/dev/www/estadao/arquivoweb/] strip per-dir prefix: D:/dev/www/estadao/arquivoweb/old.htm -> old.htm
[rid#200fa90/initial/redir#1] (3) [per-dir D:/dev/www/estadao/arquivoweb/] applying pattern '^old\.htm$' to uri 'old.htm'
[rid#200fa90/initial/redir#1] (2) [per-dir D:/dev/www/estadao/arquivoweb/] rewrite old.htm -> file.php?/arquivoweb/old.htm
[rid#200fa90/initial/redir#1] (3) split uri=file.php?/arquivoweb/old.htm -> uri=file.php, args=/arquivoweb/old.htm
[rid#200fa90/initial/redir#1] (3) [per-dir D:/dev/www/estadao/arquivoweb/] add per-dir prefix: file.php -> D:/dev/www/estadao/arquivoweb/file.php
[rid#200fa90/initial/redir#1] (2) [per-dir D:/dev/www/estadao/arquivoweb/] strip document_root prefix: D:/dev/www/estadao/arquivoweb/file.php -> /arquivoweb/file.php
[rid#200fa90/initial/redir#1] (1) [per-dir D:/dev/www/estadao/arquivoweb/] internal redirect with /arquivoweb/file.php [INTERNAL REDIRECT]
[rid#20e6c70/initial/redir#2] (3) [per-dir D:/dev/www/estadao/arquivoweb/] strip per-dir prefix: D:/dev/www/estadao/arquivoweb/file.php -> file.php
[rid#20e6c70/initial/redir#2] (3) [per-dir D:/dev/www/estadao/arquivoweb/] applying pattern '^old\.htm$' to uri 'file.php'
[rid#20e6c70/initial/redir#2] (3) [per-dir D:/dev/www/estadao/arquivoweb/] strip per-dir prefix: D:/dev/www/estadao/arquivoweb/file.php -> file.php
[rid#20e6c70/initial/redir#2] (3) [per-dir D:/dev/www/estadao/arquivoweb/] applying pattern '^new\.htm$' to uri 'file.php'
[rid#20e6c70/initial/redir#2] (1) [per-dir D:/dev/www/estadao/arquivoweb/] pass through D:/dev/www/estadao/arquivoweb/file.php

2 个答案:

答案 0 :(得分:0)

不确定new.htm会发生什么,因为日志似乎只涵盖old.htm的情况。但是,尝试将NS标志添加到old.htm重写规则,以防止在引入PHP脚本后触发子请求。

答案 1 :(得分:0)

尝试另外检查原始请求的网址,而不仅仅是当前网址:

RewriteCond %{THE_REQUEST} ^GET\ /old\.html
RewriteRule ^old\.htm$ file.php?%{REQUEST_URI} [L]
RewriteRule ^new\.htm$ old.htm [L]