How do I rewrite a URL in ASP.NET?
I would like users to be able to go to
http://www.website.com/users/smith
instead of
http://www.website.com/?user=smith
The concept of URL rewriting is simple. When a client sends a request to the Web server for a particular URL, the URL rewriting module analyzes the requested URL and changes it to a different URL on the same server.
URL rewriting is the process of intercepting an incoming Web request and redirecting the request to a different resource. When performing URL rewriting, typically the URL being requested is checked and, based on its value, the request is redirected to a different URL.
Try the Managed Fusion Url Rewriter and Reverse Proxy:
http://urlrewriter.codeplex.com
The rule for rewriting this would be:
# clean up old rules and forward to new URL RewriteRule ^/?user=(.*) /users/$1 [NC,R=301] # rewrite the rule internally RewriteRule ^/users/(.*) /?user=$1 [NC,L]
Microsoft now ships an official URL Rewriting Module for IIS: http://www.iis.net/download/urlrewrite
It supports most types of rewriting including setting server variables and wildcards.
It also will exist on all Azure web instances out of the box.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With