4

I want to perform a redirection like this:

http://www.example.com/something1
http://www.example.com/something2
http://www.example.com/something3

to

http://www.example.com/something1.aspx
http://www.example.com/folder/something2.pdf
http://www.example.com/something3.aspx?id=10

and still show the original URL in the browser (under the hood redirect)

The environment is IIS 6 / Asp.Net 3.5 on Windows Server 2003 SP2

How would I do this using web.config or IIS.

I know how to handle redirects if I can map an extension to the aspnet_isapi.dll and use Context.RewritePath(string) but I don't know how to do that for URLs that don't have extensions.

Dale K
  • 25,246
  • 15
  • 42
  • 71
Vaibhav Garg
  • 3,630
  • 3
  • 33
  • 55

3 Answers3

1

If you are able to move to ASP.NET 4 then there is a lot more support for extentionless URL rewriting.

However, if you have to use ASP.NET 3.5/IIS6 you can use ScottGu's blog post here:

http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

Curtis
  • 101,612
  • 66
  • 270
  • 352
  • I am aware of that and upgrading the server software is not really an option. thanks anyway. – Vaibhav Garg Jan 04 '12 at 13:13
  • @VaibhavGarg won't approach 2 in the link work for you? At best, you might be able to use the rewriter section of the web.config. At worst, you have to write an HttpModule to handle it via code and update the web.config to use it. – Brian Dishaw Jan 04 '12 at 13:24
  • You are right, I spoke too soon. I am trying that approach and will report back after that. – Vaibhav Garg Jan 04 '12 at 13:29
  • unfortunately the HTTPModule doesnt get called for URLs without extensions or extensions that are not registered in IIS6.. any ideas? – Vaibhav Garg Jan 04 '12 at 15:41
  • creating a wildcard entry made it work. just testing to see if it works fully – Vaibhav Garg Jan 04 '12 at 15:52
1

If you must stick with IIS6 and/or older .Net platform, there is an excellent tool from Helicon Tech that implements apache style .htaccess rules for the Microsoft IIS platform. They have a paid version but also a free version. The free version is limited to only processing one rules file, while the paid version can have many rules files that can be nested into a hierarchical directory structure.

I've been using the free version for a couple years and it works great. The only catch is that you must have access to the server (can't do this on a shared hosting environment unless your host already supports it).

HeliconTech ISAPI Rewrite

EDIT: Just to clarify, it does support all major types of redirects including proxying content from one URL through to whatever presentation URL you want. Proxy Content Example Documentation

BenSwayne
  • 16,810
  • 3
  • 58
  • 75
0

Under IIS configure a custom 404 error page e.g. error404.aspx which resides in your site. Within the error404.aspx you can access the original URL I think its Request.RawUrl (you may have to check that), then you can build you redirection or transfer whichever you prefer.

This may help Accessing original URL in IIS7 404 redirect page

As may this http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/80cb8d8d-8fd8-4af5-bb3b-4d11fff3ab9c.mspx?mfr=true

Dale K
  • 25,246
  • 15
  • 42
  • 71