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?