将规则转换为web.config

时间:2013-04-23 22:31:33

标签: .htaccess mod-rewrite redirect web-config

有谁能告诉我下面的重写对web.config文件的转换是什么?

RewriteEngine On
RewriteRule ^/(credits|content)/?$ switch.php?view=$1

或者,如果有任何在线转换工具会很棒。

由于

修改

例如:

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

将是:

<rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^example\.com$" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="http://www.example.com/{R:1}" />
    </rule>
  </rules>
</rewrite>

2 个答案:

答案 0 :(得分:1)

我无法确切地告诉您如何转换您提供的规则(遗憾的是我对.htaccess或web.config并不好),但是IIS Manager中内置了一个可以转换的便利工具。 htaccess将规则重写为IIS URL重写规则。

这里描述了它的用法:

http://www.iis.net/learn/extensions/url-rewrite-module/importing-apache-modrewrite-rules

答案 1 :(得分:0)

这将转换2种传入的URL,如下所示:

http[s]://yoursite.com/credits => switch.php.view=credits
http[s]://yoursite.com/credits/ => switch.php.view=credits
http[s]://yoursite.com/content => switch.php.view=content
http[s]://yoursite.com/content/ => switch.php.view=content

Nb:此规则不会在网址中保留参数,例如:

http[s]://yoursite.com/credits?param1=aa&param2=bb => switch.php.view=credits
http[s]://yoursite.com/credits/?param1=aa&param2=bb => switch.php.view=credits
http[s]://yoursite.com/content?param1=aa&param2=bb => switch.php.view=content
http[s]://yoursite.com/content/?param1=aa&param2=bb => switch.php.view=content