I have two websites being served on IIS 7.5 Windows Server 2008, with one site (projects.com) recently moved so that it now sits under the 2nd site (mainsite.org). This sub-site has numerous resources such as docs, PDFs, MP3s, PPts, etc..., which many sites have links to and people have bookmarks for.

I have been asked to write a rewrite/redirect rule so that when a resource link is pointed to the sub-site's old URLs the user is redirected to where it now sits on the new site (without receiving a 404).

The structure looks something like this:

Old URLs for projects.com:

New URLs for mainsite.org:

The inbound rule, which was written under projects.com, looks like this, and is for all practical purposes working:

[rule name="ABC resources redirect" stopProcessing="true"]
    [match url="^~abc/assets/(\w+)/(\w+)\.(\w+)" /]
    [action type="Redirect" url="http://mainsite.org/abc/assets/{R:1}/{R:2}.{R:3}" appendQueryString="false" /]

*where {R:1}/{R:2}.{R:3} = {subfolder}/{filename}.{ext}

Now my problem is that if the link to the resource is pointed to the old URL, the resource requested must continue to exist under the old projects.com site AND an identical copy be present under the new site as well. If not, a 404 error is displayed rather than a redirect occurring.

This means having to keep the same resource in two places, and this kind of redundancy is not good.

Additional issue: when I go directly to the PDF file at: projects.com/~abc/assets/pdfs/anchors.pdf, I am properly redirected to: mainsite.org/abc/assets/pdfs/anchors.pdf and the PDF file opens in the browser

However, when I go to other mime types: projects.com/~abc/assets/docs/questions.doc OR projects.com/~abc/assets/ppt/grand_opening.ppt, the documents automatically download (or a prompt to 'save' is displayed, depending on which browser I use).

But after the download has occurred, the URL in the address bar does not reflect the redirect, it remains the old URL (a little confusing), though the documents are being downloaded from the mainsite.org site.

I feel like perhaps my approach is conceptually flawed. Any suggestions for resolving this redundancy issue?


1 Answer 1


It sounds like your IIS rewrite rule is more complex than it probably needs to be. Try this one:

<rule name="ABC resources redirect" enabled="true" stopProcessing="true">
    <match url="^~abc/assets/(.*)" ignoreCase="true" /> 
    <action type="Redirect" url="http://mainsite.org/abc/assets/{R:1}" />

That should 301 redirect URLs containing ~abc/assets/(followed by a file with any file extension and case) to the new site's URL.

You can test and modify this using the IIS "Test pattern" tool as covered here: Microsoft IIS.net - Testing Rewrite Rule Patterns

Also be sure to completely clear the cache in your browser between each test.

If you still have an issue with mime types, then I'd suggest posting another question specific to that.

  • 1
    Thank you Dan. The above works much better. I was being too specific for my own good. I will post a 2nd question regarding the mime type problem.
    – krausdogs
    Commented Jan 8, 2014 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.