![](/img/trans.png)
[英].NET: Redirect from domain and subfolder to new domain, retaining path and querystring, using httpredirect in web.config
[英]Redirect from subfolder to new domain?
我不知道 ASP.NET。 我最近開始學習PHP。 但是我遇到了 IIS 托管的問題。 其實在里面不是問題,是我想做的事。 我在這里檢查並谷歌應用了不同的規則,但它確實對我有用。 所以我在這里請求你們的幫助。
你能為我的 web.config 寫一個規則嗎?
我需要從子文件夾到新域的 301 重定向。
這是它的樣子
domain.com/folder/* ----> newdomain.com
先感謝您!
我嘗試了不同的規則,試圖使其適應我的需要,但沒有成功。
以下規則實現了您所描述的重定向。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Test" stopProcessing="true">
<match url="folder/(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain.com$" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="http://newdomain.com" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
<match url="folder/(.*)" />
部分將檢查 URL 並匹配所有以folder/
開頭的請求。<add input="{HTTP_HOST}" pattern="^domain.com$" />
將匹配頂級域<action type="Redirect" url="http://newdomain.com" />
指定請求將重定向到哪里redirectType="Permanent"
將redirectType="Permanent"
的狀態碼設置為 301。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.