how does URL rewrite work in plain english

2019-05-08 11:47发布

问题:

I have read a lot about URL rewriting but I still don't get it.

I understand that a URL like

http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=19

can be replaced with a friendlier one like

http://www.example.com/Blog/2006/12/19/

and the server code can remain unchanged because there is some filter which transforms the new URL and sends it to the old, but does it replace the URLs in the HTML of the response too?

If the server code remains unchanged then it is possible that in my returned HTML code I have links like:

http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=20
http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=21
http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=22

This defeats the purpose of having the nice URLs if in my page I still have the old ones.

Does URL rewriting (with a filter or something) also replace this content in the HTML?

Put another way... do the rewrite rules apply for the incoming request as well as the HTML content of the response?

Thank you!

回答1:

The URL rewriter simply takes the incoming URL and if it matches a certain pattern it converts it to a URL that the server understands (assuming your rewrite rules are correct).

It does mean that a specific resource can be accessed multiple ways, but this does not "defeat the point", as the point is to have nice looking URLs, which you still do.

They do not rewrite the outgoing content, only the incoming URL.