【发布时间】:2016-08-09 19:02:01
【问题描述】:
我需要将一个站点从 linux (apache) 迁移到 windows (iis),但是,我遇到了很大的麻烦:
.htaccess
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>
我尝试了很多组合,并阅读了 Microsoft 的教程 (http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#Rule_conditions),但我无法理解其中的工作原理。现在,网站坏了。有人可以帮我翻译一下吗?
【问题讨论】:
标签: apache .htaccess mod-rewrite iis