What is URL rewriting and what are it’s common uses? We’ll look to answer these questions in this article. URL rewriting can be defined as intercepting an HTTP call to a particular URL and redirecting it to a different URL, in effect “rewriting” the incoming URL request.
This is normally done by checking the incoming URL request and based on its value, redirect the request to a different URL.
Looking at the URL’s on various web sites, we find very complicated URLs
URLs should normally follow the following guidelines for better usability.
- Easy to remember
- Should be as short as possible.
- User should be able to visualize the structure of the web site.
- User should be able to access different content of the site by changing parts of the URL.
The URL shown below doesn’t follow any of the guidelines listed. The first three points are self-explanatory. Given below is another URL
It is very easy to say what information is going to be displayed by this URL, it’s C# forum on the web site. The above URL not only follows the first three guidelines, but also the last. Removing the last part of the URL would mean
This would display all the names of the forum categories under .NET.
The common uses of URL rewriting are
- URL rewriting is usually used to shorten long URLs into short ones
- Giving a better 404-error message.
- Avoiding broken links in case of web site restructuring.
URL rewriting with ASP 3.0 could only be done with writing an ISAPI filter, but with ASP.NET, there are other methods by which this can be achieved. We can implement ISAPI filters or create HTTP modules.