This post describes some of the tips and tricks that one may find useful when solving URL-based problems for their web server or web site. Each tip/trick has a description of a problem and then an example of how it can be solved with IIS 7 URL Rewrite Module.
- Add or Remove Trailing Slash
- Enforce Lower Case URLs
- Canonical Hostnames
- Redirect to HTTPS
- Return HTTP 503 Status Code in Response
- Prevent Image Hotlinking
- Reverse Proxy to Another Site/Server
- Preserve Protocol Prefix in Reverse Proxy
- Rewrite/Redirect Based on Query String Parameter
- Avoid Rewriting of Requests for ASP.NET Web Resources
1. Add or Remove Trailing Slash
Many web applications use “virtual URLs” – that is the URLs that do not directly map to the file and directory layout on web server’s file system. An example of such application may be an ASP.NET MVC application with URL format similar to this: http://stackoverflow.com/questions/60857/modrewrite-equivalent-for-iis-7-0 or a PHP application with URL format that looks like this: http://ruslany.net/2008/11/url-rewrite-module-release-to-web/. If you try to request these URLs with or without trailing slash you will still get the same page. That is OK for human visitors, but may be a problem for search engine crawlers as well as for web analytics services. Different URLs for the same page may cause crawlers to treat the same page as different pages, thus affecting the page ranking. They will also cause Web Analytics statistics for this page to be split up.
Continue reading “10 URL Rewriting Tips and Tricks”