[英]mod_rewrite - internal to Apache, or redirect-based?
我对这个问题的答案有 90% 的把握,但我想是肯定的:
默认情况下(例如不使用 301 修饰符),mod_rewrite 是否在 Apache 内部路由或通过 http 标头或其他方法重定向客户端?
我所有的直觉、研究和经验都表明重定向是在内部完成的。 通过“内部”,我的意思是客户端没有注意到 mod_rewrite 正在使用的事实。 例如,考虑以下规则:
RewriteRule ^([^/]+)$ dispatcher.html?cat=$1
当发出适用此规则的请求时(例如example.com/testing
),请求被重定向(例如到example.com/dispatcher.html?cat=testing
)。 我对 mod_rewrite 的理解是该模块只是重写了请求,因此看起来原始请求来自example.com/dispatcher.html?cat=testing
。
这个对吗?
默认情况下(例如不使用 301 修饰符),mod_rewrite 是否在 apache 内部路由或通过 http 标头或其他方法重定向客户端?
您展示的示例将在内部重写。
If you explicitly force a full URL, a header redirect will take place except (if I read the docs right) if the full URL points to the same domain as is currently being processed, in which case the part specifying the server will be stripped,并执行了内部重定向。
文档中的此列表显示了所有可能的情况:
Given Rule Resulting Substitution
---------------------------------------------- ----------------------------------
^/somepath(.*) otherpath$1 invalid, not supported
^/somepath(.*) otherpath$1 [R] invalid, not supported
^/somepath(.*) otherpath$1 [P] invalid, not supported
---------------------------------------------- ----------------------------------
^/somepath(.*) /otherpath$1 /otherpath/pathinfo
^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^/somepath(.*) /otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^/somepath(.*) http://thishost/otherpath$1 [P] doesn't make sense, not supported
---------------------------------------------- ----------------------------------
^/somepath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
via external redirection
^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
via external redirection
(the [R] flag is redundant)
^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
via internal proxy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.