Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

web.config

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

1 Answer

up vote 2 down vote accepted

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).

share|improve this answer
    
@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? –  Zach Shallbetter 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. –  Zach Shallbetter 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. –  Zach Shallbetter Apr 26 '11 at 21:18
    
I resolved this issue by moving the rule to the top of the list. –  Zach Shallbetter Apr 28 '11 at 18:43
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.