Reputation: 9163
I'm 90% sure of the answer to this question, but I'd like to be positive:
By default (e.g. not using the 301 modifier), does mod_rewrite route internally within Apache or redirect the client via http headers or some other method?
All of my intuition, research, and experience indicates that the redirection is done internally. By 'internally', I mean that the client is oblivious to the fact that mod_rewrite is in use. For example, consider the following rule:
RewriteRule ^([^/]+)$ dispatcher.html?cat=$1
When a request is made for which this rule applies (e.g. example.com/testing
), the request is redirected (e.g. to example.com/dispatcher.html?cat=testing
). My understanding of mod_rewrite is that the module simply rewrites the request so it appears that the original request came to example.com/dispatcher.html?cat=testing
.
Is this correct?
Upvotes: 0
Views: 3602
Reputation: 449395
By default (e.g. not using the 301 modifier), does mod_rewrite route internally within apache or redirect the client via http headers or some other method?
The example you show will be rewritten internally.
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, and an internal redirect executed.
This list from the docs shows all possible scenarios:
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
Upvotes: 4