R=301 在这种情况下是否像 [END] 指令一样起作用?
不,END 无效,但 L(最后一个)有效。请理解END 的行为与L 不同。
因此 Apache 向浏览器发送301,浏览器进行完全重定向,然后再次向 Web 服务器发送 /foo2,然后执行第 2 条和第 3 条规则。
更新:
感谢下面@MrWhite 的评论,我已经运行了这个测试,同时将重写日志保存在trace4。
配置启用重写日志记录:
LogLevel info rewrite:trace4
以下是我的 Apache 错误日志中的其他日志。请注意,我的本地主机名是localhost,我的DocumentRoot 是/www/root。
步骤:应用规则#1,URI是/foo3:
strip per-dir prefix: /www/root/foo3 -> foo3
applying pattern '^foo3$' to uri 'foo3'
rewrite 'foo3' -> 'foo2'
add per-dir prefix: foo2 -> /www/root/foo2
explicitly forcing redirect with http://localhost/www/root/foo2
步骤:应用规则#2,URI是http://localhost/www/root/foo2(注意你的RewriteBase /还没有生效):
applying pattern '^foo2$' to uri 'http://localhost/www/root/foo2'
步骤:应用规则#3,URI是http://localhost/www/root/foo2:
applying pattern '^foo1$' to uri 'http://localhost/www/root/foo2'
步骤:通过使用您的RewriteBase 值剥离DocumentRoot 来应用外部重定向301:
trying to replace prefix /www/root/ with /
add subst prefix: foo2 -> foo2
escaping http://localhost/foo2 for redirect
redirect to http://localhost/foo2 [REDIRECT/301]
步骤:应用规则#1,URI是/foo2:
strip per-dir prefix: /www/root/foo2 -> foo2
applying pattern '^foo3$' to uri 'foo2'
步骤:应用规则#2,URI是/foo2:
strip per-dir prefix: /www/root/foo2 -> foo2
applying pattern '^foo2$' to uri 'foo2'
rewrite 'foo2' -> 'foo1'
步骤:应用规则#3,URI是/foo1:
add per-dir prefix: foo1 -> /www/root/foo1
strip per-dir prefix: /www/root/foo1 -> foo1
applying pattern '^foo1$' to uri 'foo1'
rewrite 'foo1' -> 'index.php'
步骤:内部重写为/index.php:
add per-dir prefix: index.php -> /www/root/index.php
trying to replace prefix /www/root/ with /
add subst prefix: index.php -> /index.php
internal redirect with /index.php [INTERNAL REDIRECT]
步骤:应用规则#1,URI是/index.php:
strip per-dir prefix: /www/root/index.php -> index.php
applying pattern '^foo3$' to uri 'index.php'
步骤:应用规则#2,URI是/index.php:
strip per-dir prefix: /www/root/index.php -> index.php
applying pattern '^foo2$' to uri 'index.php'
步骤:应用规则#3,URI是/index.php:
strip per-dir prefix: /www/root/index.php -> index.php
applying pattern '^foo1$' to uri 'index.php'
步骤:停止规则处理,URI为/index.php:
pass through /www/root/index.php
我在上面添加了详细的跟踪记录和我的step 评论,以说明L 是一个副作用,其中规则处理没有完全停止。然而,mod_rewrite 引擎试图在 无效 的 URI 上应用剩余规则,即 http://localhost/www/root/foo2 这些规则不会执行,结果将是完全重定向。