RedirectPermanent 与 RewriteRule

RedirectPermanent 与 RewriteRule

我目前有一个 perm_redirects.conf 文件,它被包含在我的 apache 配置堆栈中,其中有以下格式的行

RedirectPermanent /old/url/path /new/url/path

看起来我需要使用绝对 URL 作为新路径,例如: http://example.com/new/url/path。在我收到的日志中“不完整的重定向目标/new/url/path已更正为http://example.com/new/url/path“”。(释义)。

在 2.2 版文档中RewriteRule,底部显示以下内容为有效重定向,其中重定向右侧仅显示 url 路径而不是绝对 URL:

RewriteRule ^/old/url/path(.*) /new/url/path$1 [R]

但我似乎无法让该格式复制该RedirectPermanent版本的功能。这可能吗?

答案1

工作流管理器:

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=permanent]。默认是临时重定向。 (2) 您不希望只使用 [L],因为这会导致最终用户看不到内部重定向(不是由 L 引起的,默认操作“”是内部重定向)。RedirectPermanent 会向最终用户生成 3xx 响应。您可以添加 L,即 [R=permanent,L],以阻止 mod_rewrite 处理任何其他规则。

相关内容