0

mod-rewrite question.

Why the following code

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^search/(.*)$ http://www.example.com/forms/index.php?i=$1 [QSA,L]

results in the url changing from

http://www.example.com/search/foo/bar

to

http://www.example.com/forms/index.php?i=foo/bar

while the following code:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^search/(.*)$ /forms/index.php [L]

does not change the input url?

Any insight?

Thanks.

4

1 回答 1

1

因为当你有http://www.example.com, mod_rewrite隐式重定向时,它与放入R规则的标志相同。

mod_rewrite 文档中,在“替换字符串”下它说:

绝对网址

如果指定了绝对 URL,mod_rewrite 会检查主机名是否与当前主机匹配。如果是这样,则方案和主机名将被删除,并且生成的路径将被视为 URL 路径。否则,将对给定 URL 执行外部重定向。要强制将外部重定向回当前主机,请参见下面的 [R] 标志。

于 2013-10-26T22:10:41.657 回答