My company's website has a directory http://website.net/files that has obscure data half of the company uses. It doesn't fit with our new site structure and I'd like to move it to a new server with the dns http://files.website.net. The problem I'm having is that many of the users will still have links similar to http://website.net/file/app.exe

I've been told that URL Rewrite is the best option to force a redirect while maintaining the query but I seem to be missing something. Any help would be appreciated.

enter image description here


<?xml version="1.0" encoding="UTF-8"?>
        <rule name="wordpress" patternSyntax="Wildcard">
          <match url="*" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          <action type="Rewrite" url="index.php" />
                <rule name="files" stopProcessing="true">
                    <match url="^files/(.*)" ignoreCase="true" />
                    <action type="Redirect" url="http://downloads.openeye.net/files/{R:1}" logRewrittenUrl="true" />
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" prefixLanguageFilePath="" path="/index.php?error=404" responseMode="ExecuteURL" />

Multiple issues in your screenshot:

  1. The regex pattern you have in the Pattern field is only going to match numbers after the last slash in the URL. "files/subdir/1234" will match. "files/subdir/app.exe" will not match. You need ^files/([_0-9a-z-]+)/(.*) in the pattern field. Or if all you need is anything with the /files, you can use ^files/(.*). The Test Pattern feature is your friend here.

  2. I would check Ignore Case, but that's up to you for your particular scenario.

  3. Action type should be "Redirect"

  4. Assuming you're using ^files/(.*) for your regex pattern, the Redirect URL should be: http://downloads.openeye.net/files/{R:1}

This would mean that someone who enters http://yourdomain.com/files/whatever.exe would get redirected to http://downloads.openeye.net/files/whatever.exe

Or if they have a longer URL like http://yourdomain.com/files/dir1/dir2/whatever.exe, it will still get tacked on the end of the new URL (http://downloads.openeye.net/files/dir1/dir2/whatever.exe).

  • @user78940 Thanks for your help! I went ahead and adjusted the inbound rule with your specifications and changed the above picture. I now seem to be receiving simply a 404 error from the root page. Now this is WordPress so it's entirely possible that my 404 is circumventing the redirect. redesign.openeye.net/files/file.exe what do you think? Apr 26 '11 at 13:53
  • Just to be sure I'm not crazy, I tested this in my dev server and it works for me. What URL does it show in the address bar when you get the 404? Is it the correct (redirected) URL? And is the 404 page the IIS 404 error page?
    – user78940
    Apr 26 '11 at 16:47
  • This is the page redesign.openeye.net/files/file.exe. Apr 26 '11 at 17:57
  • Do you think WordPress could be undermining the IIS7 URL Rewrite? I added a copy of my web.config file to the post. Apr 26 '11 at 21:18
  • I resolved this issue by moving the rule to the top of the list. Apr 28 '11 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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