将Apache mod_rewrite文件转换为IIS URL重写

时间:2014-10-22 22:38:01

标签: apache mod-rewrite iis web-config

我对IIS没有很好的了解,我需要将以下htaccess文件转换为web.config,以便在IIS下启用URL重写。

RewriteEngine On
RewriteRule ^index.html$ index.php [L]
RewriteRule ^/?([0-9a-zA-Z_-]+)/?$ rewrite.php?param1=$1 [L]
RewriteRule ^/?([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)/?$ rewrite.php?param1=$1&param2=$2 [L]
RewriteRule ^/?([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)/([^/]+)/?$ rewrite.php?param1=$1&param2=$2&param3=$3 [L]

由于

1 个答案:

答案 0 :(得分:0)

您的规则可以转换为IIS 网址重写模块规则,如下所示:

<rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^index.html$" ignoreCase="false" />
      <action type="Rewrite" url="index.php" />
    </rule>
    <rule name="Imported Rule 2" stopProcessing="true">
      <match url="^([0-9a-zA-Z_-]+)/?$" ignoreCase="false" />
      <action type="Rewrite" url="rewrite.php?param1={R:1}" appendQueryString="false" />
    </rule>
    <rule name="Imported Rule 3" stopProcessing="true">
      <match url="^([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)/?$" ignoreCase="false" />
      <action type="Rewrite" url="rewrite.php?param1={R:1}&amp;param2={R:2}" appendQueryString="false" />
    </rule>
    <rule name="Imported Rule 4" stopProcessing="true">
      <match url="^([0-9a-zA-Z_-]+)/([0-9a-zA-Z_-]+)/([^/]+)/?$" ignoreCase="false" />
      <action type="Rewrite" url="rewrite.php?param1={R:1}&amp;param2={R:2}&amp;param3={R:3}" appendQueryString="false" />
    </rule>
  </rules>
</rewrite>

有关详细信息,请参阅this answer