web.config中的301路径重定向

时间:2018-11-13 13:40:17

标签: xml apache azure url web-config

我正在尝试使Web重定向适用于我的wordpress网站,但是重定向URL没有任何反应。

该站点是wordpress,并且具有一个如下所示的现有web.config文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
            <rule name="WordPress" patternSyntax="Wildcard">
                <match url="*"/>
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                    </conditions>
                <action type="Rewrite" url="index.php"/>
            </rule>
    </rules>
    </rewrite>
    <staticContent>
            <mimeMap fileExtension=".json" mimeType="application/json" />
     </staticContent>
  </system.webServer>
</configuration>

我希望该网址从/ path / to / old重定向到/ path / to / new,并在第一条规则之后添加以下内容:

<rule name="Redirect" stopProcessing="true">
  <match url="^path/to/new" />
  <action type="Redirect" url="http:/www.site.com/path/to/new" redirectType="Found"/>
</rule>

因此完整的代码如下:

   <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
                <rule name="WordPress" patternSyntax="Wildcard">
                    <match url="*"/>
                        <conditions>
                            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
                        </conditions>
                    <action type="Rewrite" url="index.php"/>
                </rule>
               <rule name="Redirect" stopProcessing="true">
                 <match url="^path/to/new" />
                 <action type="Redirect" url="http:/www.site.com/path/to/new" redirectType="Found"/>
               </rule>
        </rules>
        </rewrite>
        <staticContent>
                <mimeMap fileExtension=".json" mimeType="application/json" />
         </staticContent>
      </system.webServer>
    </configuration>

我是web.config的新手,但以前使用过.htaccess。有点不明白为什么它不起作用–当我输入应该重定向的URL时,网站上没有任何反应。

2 个答案:

答案 0 :(得分:0)

据我所知,规则按其顺序排列优先级,这意味着您的通配符规则会在特定规则之前处理所有请求,然后这些请求与模式不匹配。

尝试将重定向规则放在 WordPress 规则之前,并删除 stopProcessing 属性。

希望有帮助!

答案 1 :(得分:0)

根据IIS文档,网址为 visualization

看起来就像放

一样简单
 <httpRedirect enabled="true" destination="http:/www.site.com/path/to/new" />
甚至在重写mod之前

<system.webServer>的根。您可以尝试一下,让我们知道是否适合您。

相关问题