Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET URL Rewriting

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 
like image 472
GateKiller Avatar asked Aug 05 '08 13:08

GateKiller


People also ask

What is URL rewriting in asp net?

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.

What is URL rewriting in ASP NET MVC?

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.


2 Answers

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] 
like image 140
Nick Berardi Avatar answered Oct 11 '22 13:10

Nick Berardi


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.

like image 41
Sam Saffron Avatar answered Oct 11 '22 13:10

Sam Saffron