【问题标题】:Convert htaccess rewrite rule to web.config将 htaccess 重写规则转换为 web.config
【发布时间】:2017-09-13 17:10:17
【问题描述】:

我一直在尝试将 .htaccess 规则转换为 web.config 但没有运气,我尝试了在线工具来执行此操作并尝试了一些类似的规则,但我一无所获,这就是我得到的:

// .htaccess
RewriteCond %{HTTP_HOST} ^(?:www\.)?oldURL$ [NC]
RewriteRule ^/?e:/folder1/folder2/folder3(/.*)?$ http://newURL$1 [L,NE,R=301,NC]

我在web.config中试过这条规则:

<rule name="Redirect files" stopProcessing="true">
      <match url="^/?e:/folder1/folder2/folder3(/.*)?$" ignoreCase="true" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^(?:www\.)?oldURL$" />
      </conditions>
      <action type="Rewrite" url="http://newURL{R:1}" />
</rule>

有人能告诉我我在这里缺少什么吗?谢谢。

【问题讨论】:

    标签: php regex .htaccess mod-rewrite iis


    【解决方案1】:

    我不知道为什么 web.config 不能重写 URL,但是重定向对我有用,我更改了操作行:

    <action type="Redirect" url="http://newURL{R:1}" redirectType="Permanent" />
    

    我删除了条件:

    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^(?:www\.)?oldURL$" />
    </conditions>
    

    现在我的所有文件都使用新 URL 提供服务。

    【讨论】:

      猜你喜欢
      • 2013-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-22
      • 2015-07-27
      • 2014-06-30
      • 2016-08-09
      • 2014-10-29
      相关资源
      最近更新 更多