【问题标题】:Rewrite rule conversion to web.config将规则转换重写为 web.config
【发布时间】:2013-05-13 23:24:40
【问题描述】:

谁能告诉我下面的重写对于 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>

【问题讨论】:

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


    【解决方案1】:

    我无法确切告诉您如何转换您提供的规则(不幸的是,我不擅长 .htaccess 或 web.config),但是 IIS 管理器中内置了一个方便的工具,可以让您转换 .htaccess 或 web.config。 htaccess 重写规则为 IIS URL 重写规则。

    这里描述了它的用法:

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

    【讨论】:

      【解决方案2】:

      这将转换 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
      

      注意:此规则不保留 URL 中的参数,例如:

      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
      

      【讨论】:

      • 感谢您的回答,但我仍然有点困惑,我将把这些我看到的示例放在哪里,看起来就像我在问题中提供的编辑。
      猜你喜欢
      • 1970-01-01
      • 2014-10-29
      • 2013-08-27
      • 1970-01-01
      • 1970-01-01
      • 2012-08-05
      • 2012-08-22
      • 2014-06-30
      • 2016-08-09
      相关资源
      最近更新 更多