在IIS7中重写URL

我公司的网站有一个目录http://website.net/files ,它隐藏了公司使用的一半数据。 它不符合我们的新的网站结构,我想将它移动到一个新的服务器与DNS http://files.website.net 。 我遇到的问题是,许多用户仍然会有类似于http://website.net/file/app.exe的链接

我被告知URL重写是强制redirect的最佳select,同时保持查询,但我似乎失去了一些东西。 任何帮助,将不胜感激。

在这里输入图像说明

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> 

截图中的多个问题:

  1. 您在“模式”字段中使用的正则expression式只会匹配url中最后一个斜杠后面的数字。 “files / subdir / 1234”将匹配。 “files / subdir / app.exe”将不匹配。 在模式字段中需要^files/([_0-9a-z-]+)/(.*) 。 或者如果你需要的只是/文件的任何东西,你可以使用^files/(.*) 。 testing模式function是你的朋友在这里。

  2. 我会检查忽略大小写,但这取决于您的特定情况。

  3. 动作types应该是“redirect”

  4. 假设您正在使用^files/(.*)作为正则expression式模式,redirectURL应为: http://downloads.openeye.net/files/{R:1} : http://downloads.openeye.net/files/{R:1} :1 http://downloads.openeye.net/files/{R:1}

这意味着inputhttp://yourdomain.com/files/whatever.exe的用户将被redirect到http://downloads.openeye.net/files/whatever.exe

或者如果他们有一个像http://yourdomain.com/files/dir1/dir2/whatever.exe更长的URL,它仍然会在新的URL的末尾&#xFF08; http://downloads.openeye.net/files /dir1/dir2/whatever.exe )。