Comparing Routing to URL Rewriting

To better understand Routing, many developers compare it to URL rewriting. After all, both approaches are useful in creating a separation between the incoming URL and what ends up handling the request. Additionally, both techniques can be used to create pretty URLs for Search Engine Optimization (SEO) purposes.
The key difference is that URL rewriting is focused on mapping one URL to another URL. For example, URL rewriting is often used for mapping old sets of URLs to a new set of URLs. Contrast that to Routing, which is focused on mapping a URL to a resource.
You might say that Routing embodies a resource-centric view of URLs. In this case, the URL represents a resource (not necessarily a page) on the Web. With ASP.NET Routing, this resource is a piece of code that executes when the incoming request matches the route. The route determines how the request is dispatched based on the characteristics of the URL — it doesn’t rewrite the URL.
Another key difference is that Routing also helps generate URLs using the same mapping rules that it uses to match incoming URLs. URL rewriting applies only to incoming requests and does not help in generating the original URL.
Another way to look at it is that ASP.NET Routing is more like bidirectional URL rewriting. However, this comparison falls short because ASP.NET Routing never actually rewrites your URL. The request URL that the user makes in the browser is the same URL your application sees throughout the entire request life cycle.

Tagged . Bookmark the permalink.

Leave a Reply