我对这个问题的答案有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的。
这是正确的吗?
发布于 2011-07-13 01:52:23
默认情况下(例如,不使用301修饰符),mod_rewrite是在
内部路由还是通过HTTP头或其他方法重定向客户端?
您显示的示例将在内部重写。
如果你显式地强制一个完整的URL,一个头重定向将会发生,除非(如果我没看错docs )如果这个完整的URL指向当前正在处理的相同的域,在这种情况下指定服务器的部分将被剥离,并执行一个内部重定向。
文档中的这个列表显示了所有可能的情况:
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 proxyhttps://stackoverflow.com/questions/6668714
复制相似问题