Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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:
projects.com/~abc/assets/pdfs
projects.com/~abc/assets/docs

New URLs for mainsite.org:
mainsite.org/abc/assets/pdfs
mainsite.org/abc/assets/docs

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" /]
[/rule]

*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?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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}" />
</rule>

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.

share|improve this answer
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. –  user34615 Jan 8 at 21:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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