Suppose you want the URL to show in the browser bar to be http://server.com/cart/ , but you want the ViewCart.aspx page to actually run when that URL request is made. That is simple - that is a single rewrite request. But! Suppose that there are links out there that have ViewCart.aspx in the URL. And you don't want that to display in the browser address bar.

So you have the situation where if someone clicks on http://server.com/ViewCart.aspx , then you want to REDIRECT to http://fcp.com/cart, but then.... (ready for this?) you want to REWRITE that request to ViewCart.aspx.

Remember, the REWRITE does not change the URL in the browser address bar. The REWRITE is a server-side operation. It merely changes what gets executed on the server side. The REDIRECT sends a message back to the browser, telling it to send its request to a different endpoint.

Here is the result:

# REDIRECT to change the address in the browser address bar
RewriteRule ^/ViewCart.aspx$   /cart   [R]

# REWRITE so that the correct page executes when /cart is the URL
RewriteRule ^/cart$  ViewCart.aspx   [L]

Last edited Oct 6, 2008 at 10:16 PM by Cheeso, version 1

Comments

okkko Jan 7, 2009 at 1:57 PM 
A little mistake in the above code, the correct way is:

# REDIRECT to change the address in the browser address bar
RedirectRule ^/ViewCart.aspx$ /cart [R]