Why do I need [R] in my RewriteRule?
I understand that the [R] flag forces a redirect to the browser. The way I understand that is that it will "redraw" the URL in the browser's address bar.
So
RewriteRule test en/students/ [R]
will take change this address: http://mydomain.com/test
to this: http://mydomain.com/en/students
But if I leave out the [R] in the above example, it SHOULD still take me to the /en/students page, should it not? My understanding is that it should still go to that page, but the ad开发者_运维问答dress bar would simply not update.
If I'm wrong about that, please disabuse me of the notion. Otherwise, I'll need help understanding why it's not working in my case? Is it because of the RewriteRules needed by WordPress after that? Does WordPress mess things up by always analysing the ACTUAL URI that was used to call up its engine, or can it access this "hidden" URI that is the product of the RewriteEngine?
Without [R]
, the request goes something like this:
- The browser requests
http://mydomain.com/test
. - The rewrite rule changes that internally to
http://mydomain.com/en/students
. - Apache returns to the browser the content of
http://mydomain.com/en/students
. The browser has no idea that the URI was changed internally.
With [R]
, the request goes something like this:
- The browser requests
http://mydomain.com/test
. - The rewrite rule sends a response to the browser, telling it to load
http://mydomain.com/en/students
instead. - The browser requests
http://mydomain.com/en/students
(and probably changes the status bar, too). - Absent any other rewrite rules, Apache returns to the browser the content of
http://mydomain.com/en/students
.
I can only guess that in the former case, Wordpress is accessing the requested URI rather than the rewritten URI.
The [R] makes the rewrite to a redirect. So the browser is send to the new url. A normal rewrite is handled by the server and the user doesn't see what tha actual target is.
精彩评论