我目前有一个perm_redirects.conf文件被包含到我的Apacheconfiguration堆栈中,我有格式的行
RedirectPermanent /old/url/path /new/url/path
它看起来像我需要使用一个绝对的URL的新path,例如: http://example.com/new/url/path : http://example.com/new/url/path 。 在日志中,我收到“不完整的redirect目标/新/ url /path已更正为http://example.com/new/url/path” 。 (转述)。
在RewriteRule的2.2文档中,在底部,他们显示以下是一个有效的redirect,只有url-paths,而不是redirect右侧的abs URL:
RewriteRule ^/old/url/path(.*) /new/url/path$1 [R]
但我似乎无法获得该格式来复制RedirectPermanent版本的function。 这可能吗?
WFM:
RewriteEngine On RewriteOptions Inherit RewriteRule ^/old/url/path(.*) /new/url/path$1 [R]
结果:
wget http://localhost/old/url/path/foo --2010-08-09 15:41:20-- http://localhost/old/url/path/foo Resolving localhost... 127.0.0.1 Connecting to localhost|127.0.0.1|:80... connected. HTTP request sent, awaiting response... 302 Found Location: http://localhost/new/url/path/foo [following] --2010-08-09 15:41:20-- http://localhost/new/url/path/foo
注意(1)你可能想要[R =永久]。 默认是一个临时redirect。 (2)您不希望只是[L],因为这将导致内部redirect对最终用户不可见(不是由L引起的,默认操作“”是内部redirect)。 RedirectPermanent为最终用户生成3xx响应。 你可以添加L,即[R = permanent,L]来阻止mod_rewrite处理更多的规则。