我需要将一个站点从linux(apache)迁移到windows(iis),但是我遇到了很大的麻烦:
RewriteEngine On
RewriteRule %{REQUEST_FILENAME} !-f
RewriteRule %{REQUEST_FILENAME} !-d
RewriteRule ^$ index.php [NC,L]
RewriteRule ^/$ index.php [NC,L]
RewriteRule ^download/(.+)$ download/$1 [NC,L]
RewriteRule ^([0-9]+)?$ index.php?c=resetPassword&m=show&id=$1 [NC,L]
RewriteRule ^([^/.]+)?$ index.php?c=$1 [NC,L]
RewriteRule ^([^/.]+)/?$ index.php?c=$1 [NC,L]
RewriteRule ^([^/.]+)/([A-z]+)?$ index.php?c=$1&m=$2 [NC,L]
RewriteRule ^([^/.]+)/([A-z]+)/?$ index.php?c=$1&m=$2 [NC,L]
RewriteRule ^([^/.]+)/([0-9]+)?$ index.php?c=$1&m=show&id=$2 [NC,L]
RewriteRule ^([^/.]+)/([0-9]+)/?$ index.php?c=$1&m=show&id=$2 [NC,L]
RewriteRule ^([^/.]+)/([A-z]+)/([0-9]+)?$ index.php?c=$1&m=$2&id=$3 [NC,L]
RewriteRule ^([^/.]+)/([A-z]+)/([0-9]+)/?$ index.php?c=$1&m=$2&id=$3 [NC,L]
当我尝试翻译到IIS平台时,我尝试了它:
<rewrite>
<rules>
<rule name="block favicon" stopProcessing="true">
<match url="favicon\.ico" />
<action type="CustomResponse" statusCode="404" subStatusCode="1"
statusReason="The requested file favicon.ico was not found"
statusDescription="The requested file favicon.ico was not found" />
</rule>
<rule name="Rule Mapping Root" stopProcessing="true">
<match url="^/" ignoreCase="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/" />
</conditions>
<action type="Rewrite" url="index.php"/>
</rule>
<rule name="Rule Mapping Download" stopProcessing="true">
<match url="^download/(.+)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_URI}" pattern="^download/(.+)$" />
</conditions>
<action type="Rewrite" url="download/{R:1}" appendQueryString="true" />
</rule>
<rule name="Rule Mapping Reset Pass" stopProcessing="true">
<match url="^([0-9]+)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_URI}" pattern="^([0-9]+)" />
</conditions>
<action type="Rewrite" url="index.php?c=resetPassword&m=show&id={R:1}" appendQueryString="true" />
</rule>
<rule name="Rule Mapping Index 10" stopProcessing="true">
<match url="^([^/.]+)$" ignoreCase="true" />
<conditions>
<add input="{REQUEST_URI}" pattern="^([^/.]+)$" />
</conditions>
<action type="Rewrite" url="index.php?c={R:1}" appendQueryString="true" />
</rule>
<rule name="Rule Mapping Index 11" stopProcessing="true">
<match url="^([^/.]+)/$" ignoreCase="true" />
<action type="Rewrite" url="index.php?c={R:1}" appendQueryString="true" />
</rule>
<rule name="Rule Mapping Index 20" stopProcessing="true">
<match url="^([^/.]+)/([A-z]+)$" ignoreCase="true" />
<action type="Rewrite" url="index.php?c={R:1}&m={R:2}" appendQueryString="true" />
</rule>
<rule name="Rule Mapping Index 21" stopProcessing="true">
<match url="^([^/.]+)/([A-z]+)/$" ignoreCase="true" />
<action type="Rewrite" url="index.php?c={R:1}&m={R:2}" appendQueryString="true" />
</rule>
<rule name="Rule Mapping Index 30" stopProcessing="true">
<match url="^([^/.]+)/([0-9]+)$" ignoreCase="true" />
<action type="Rewrite" url="index.php?c={R:1}&m=show&id={R:2}" appendQueryString="true" />
</rule>
<rule name="Rule Mapping Index 31" stopProcessing="true">
<match url="^([^/.]+)/([0-9]+)/$" ignoreCase="true" />
<action type="Rewrite" url="index.php?c={R:1}&m=show&id={R:2}" appendQueryString="true" />
</rule>
<rule name="Rule Mapping Index 40" stopProcessing="true">
<match url="^([^/.]+)/([A-z]+)/([0-9]+)$" ignoreCase="true" />
<action type="Rewrite" url="index.php?c={R:1}&m={R:2}&id={R:3}" appendQueryString="true" />
</rule>
<rule name="Rule Mapping Index 41" stopProcessing="true">
<match url="^([^/.]+)/([A-z]+)/([0-9]+)/$" ignoreCase="true" />
<action type="Rewrite" url="index.php?c={R:1}&m={R:2}&id={R:3}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
我尝试了很多组合,我阅读了微软的教程(http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#Rule_conditions),但我无法理解为此工作。现在,该网站已经破产。有人可以帮我翻译一下吗?
答案 0 :(得分:0)
这里在web.config中使用它我为你转换了重写为webconfig。
<rule name="rule 1f">
<match url="%{REQUEST_FILENAME}" />
<action type="Rewrite" url="/!-f" />
</rule>
<rule name="rule 2f">
<match url="%{REQUEST_FILENAME}" />
<action type="Rewrite" url="/!-d" />
</rule>
<rule name="rule 3f" stopProcessing="true">
<match url="^$" ignoreCase="true" />
<action type="Rewrite" url="/index.php" />
</rule>
<rule name="rule 4f" stopProcessing="true">
<match url="^/$" ignoreCase="true" />
<action type="Rewrite" url="/index.php" />
</rule>
<rule name="rule 5f" stopProcessing="true">
<match url="^download/(.+)$" ignoreCase="true" />
<action type="Rewrite" url="/download/{R:1}" />
</rule>
<rule name="rule 6f" stopProcessing="true">
<match url="^([0-9]+)?$" ignoreCase="true" />
<action type="Rewrite" url="/index.php?c=resetPassword&m=show&id={R:1}" />
</rule>
<rule name="rule 7f" stopProcessing="true">
<match url="^([^/.]+)?$" ignoreCase="true" />
<action type="Rewrite" url="/index.php?c={R:1}" />
</rule>
<rule name="rule 8f" stopProcessing="true">
<match url="^([^/.]+)/?$" ignoreCase="true" />
<action type="Rewrite" url="/index.php?c={R:1}" />
</rule>
<rule name="rule 9f" stopProcessing="true">
<match url="^([^/.]+)/([A-z]+)?$" ignoreCase="true" />
<action type="Rewrite" url="/index.php?c={R:1}&m={R:2}" />
</rule>
<rule name="rule 10f" stopProcessing="true">
<match url="^([^/.]+)/([A-z]+)/?$" ignoreCase="true" />
<action type="Rewrite" url="/index.php?c={R:1}&m={R:2}" />
</rule>
<rule name="rule 11f" stopProcessing="true">
<match url="^([^/.]+)/([0-9]+)?$" ignoreCase="true" />
<action type="Rewrite" url="/index.php?c={R:1}&m=show&id={R:2}" />
</rule>
<rule name="rule 12f" stopProcessing="true">
<match url="^([^/.]+)/([0-9]+)/?$" ignoreCase="true" />
<action type="Rewrite" url="/index.php?c={R:1}&m=show&id={R:2}" />
</rule>
<rule name="rule 13f" stopProcessing="true">
<match url="^([^/.]+)/([A-z]+)/([0-9]+)?$" ignoreCase="true" />
<action type="Rewrite" url="/index.php?c={R:1}&m={R:2}&id={R:3}" />
</rule>
<rule name="rule 14f" stopProcessing="true">
<match url="^([^/.]+)/([A-z]+)/([0-9]+)/?$" ignoreCase="true" />
<action type="Rewrite" url="/index.php?c={R:1}&m={R:2}&id={R:3}" />
</rule>