tags:

views:

2915

answers:

3

I have a website setup in IIS 6, let's say it's called http://www.this.com.

I have setup a redirection for this website to http://www.that.com which maintains the directory structure and query parameters as follows:

http://www.that.com$S$Q - using the option "The exact URL entered above"

This works great, whenever someone requests, for example:

http://www.this.com/subfolder/page.aspx?Id=1

then they end up at:

http://www.that.com/subfolder/page.aspx?Id=1

Now, I have one page, actually a handler, http://www.this.com/image.axd, which I do not want to redirect.

What is the syntax for that? I've read the Redirection Using Wildcards section here, but I can't work out how to do what seems to be something straight forward.

Note that image.axd is a handler so I can't just "right click" on it and set the redirection properties as it doesn't physically exist.

I also have a couple of other pages in subfolders which I do not want to redirect, for example:

http://www.this.com/subfolder/donotredirectthispage.aspx

Any help would be appreciated.

Edit: A couple of people have mentioned using ISAPI_Rewrite, for which I'm grateful, but I really don't want to introduce another complexity into the website configuration. IIS seems to imply I can acheive what I want using the ! and 0 through 9 variables.

Is it really not possible to do this using IIS?

My current workaround is to set the redirection properties on ALL folders and pages that I want to redirect except those I do not, but this is a management nightmare.

+1  A: 

You could implement a custom error page for the page not found error (404) that does the redirection for you. You'd turn off the redirection in IIS. Build the logic for the redirection in your custom error page. Then configure your web site so that 404 errors redirect to your error page.

tvanfosson
A: 

If you can install software on your IIS server, I'd recommend using a tool to rewrite your request URLs.

For IIS 6.0 I've used ISAPI_Rewrite and it works really well. It's lightweight and very configurable. There's a "Lite" version available for free and will support your requirements.

You configure the program using a text file containing rules that match HTTP requests and then write actions to perform once a rule is matched. Your instance would probably require a general redirect rule (similar to the one in IIS) and rules for your exceptions.

dariom
A: 

You should look into the possibility of using a header rewrite module, for example ISAPI_rewrite. There is a free "lite" version available that is enough for your needs.

What this can do for you is the following: Before actual pages are executed on the server, the Request headers are rewritten (or HTTP 301/302 redirects are issued) based on a configurable set of rules. The underlying server sees the remaining requests as if the client really made them in that fashion.

The following rules would leave image.axd requests alone, while redirecting everything else.

# image.axd stays unchanged ("L" is the "last rule" flag)
RewriteCond Host: www.\this\.com
RewriteRule ^.*?\bimage\.axd\b.* $0 [L]

# all requests that have not been stopped by an earlier rule
# end up here ("RP" is the "permanent redirect" flag)
RewriteCond Host: www.\this\.com
RewriteRule .* http://www.that.com$0 [RP,L]
Tomalak