[英]301 path redirect in 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時,網站上沒有任何反應。
據我所知,規則按其優先級排序,這意味着您的通配符規則會先處理所有請求,再處理特定規則,然后這些請求與模式不匹配。
嘗試將“ 重定向”規則放在WordPress規則之前,並刪除stopProcessing屬性。
希望能幫助到你!
根據IIS文檔, 網址為https://docs.microsoft.com/zh-cn/iis/configuration/system.webserver/httpredirect/
看起來就像把它一樣簡單
<httpRedirect enabled="true" destination="http:/www.site.com/path/to/new" />
到<system.webServer>
的根目錄,甚至在重寫mod之前。 您可以嘗試一下,讓我們知道是否適合您。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.