Asp.net

301 使用 asp.net web.config 文件從一個網站重定向到另一個網站

  • June 26, 2019

我的舊網站有一個 HTML 頁面,需要 301 重定向到新網站的 aspx 頁面,這兩個網站都建立在 asp.net 平台上。請建議我如何配置我的 web.config 文件來完成這項任務。目前我正在使用 Meta Refresh 來執行此操作,但這可能是 200 而不是 301。

任何幫助將不勝感激,謝謝。

我在舊網站 web.config 文件中使用了以下程式碼,但效果不佳

<configuration>
 <location path="http://example.htm">
   <system.webServer>
     <httpRedirect enabled="true" destination="http://newwebsite.com/test.aspx" httpResponseStatus="Permanent" />
   </system.webServer>
 </location>
</configuration>

在你的 web.config 文件中創建規則

<system.webServer>
   <rewrite>
     <rules>
        <rule name="URL1" stopProcessing="true">
         <match url="^abc.html" ignoreCase="true" />
         <action type="Redirect" url="Your current page path" redirectType="Permanent" />
       </rule>
     </rules>
   </rewrite>
</system.webServer>
<configuration>
   <system.webServer>
       <httpRedirect enabled="true" destination="http://uri" httpResponseStatus="Permanent" />
   </system.webServer>
</configuration>

抱歉,我沒有針對單頁的 web.config 解決方案。您需要將其放置在靠近頂部的標記頁面中:

<% RedirectPermanent("http://url", true) %>

如果它對您不起作用,請在此處發布您的標記,我會為您更新它。

引用自:https://stackoverflow.com/questions/24566035