views:

38

answers:

1

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 rewrite (with a filter or something) also replaces 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  A: 

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.

Oded
Ok, so what do I do with the hrefs in my HTML? How do I replace those?
userUMB
@userUMB - You have to change your HTML, or whatever is generating it to output the "nice" links.
Oded
@userUMB You could use relative paths ([href,includes, images, etc] to root) links instead of absolute avoiding having to change them everytime URL rewrite is altered. (eg. href="/pages/services.html"). Same goes with images and other elements.
Codex73