2015-03-25 14 views
0

嗨我想重寫我的網址:www.mydomain.com/hw/Index.aspx到www.mydomain.com/hello-world/index.aspx 。這裏是我的代碼在web.config中:ASP.NET URL重寫和標記舊URL爲301

<rule name="Redirect to WWW" stopProcessing="true"> 
     <match url="^hello-world/index.aspx" /> 
     <action type="rewrite" url="hw/Index.aspx" /> 
    </rule> 

這個問題是我有兩個網址只有相同的頁面。

  1. www.mydomain.com/hw/Index.aspx
  2. www.mydomain.com/hello-world/index.aspx

我想什麼做的是當用戶瀏覽www.mydomain.com/hw/Index.aspx 它會被標記爲301並重定向到www.mydomain.com/hello-world/index.aspx

請幫助我。

在此先感謝。

回答

0

A rewrite本質上使得IIS向用戶提供相同的頁面,它在內部重新寫入URL並將其傳遞給您的應用程序。

在另一方面,一個rewrite實際上發送該被請求的資源已經被移動到客戶端的響應(即,301)

爲了解決這個問題,改變從rewriteredirect動作類型:

<rule name="Redirect to WWW" stopProcessing="true"> 
    <match url="^hello-world/index.aspx" /> 
    <action type="redirect" url="hw/Index.aspx" /> 
</rule> 
+0

嗨DavidG,與此問題是它會始終將我的網址重定向到** www.mydomain.com/hw/Index.aspx **而不是** www.mydomain.com/hello-world/index.aspx **。我需要的是** www.mydomain.com/hello-world/index.aspx **。請指教。 – user3274033 2015-03-25 00:56:18

+0

您的規則只是回到前面,切換匹配值和動作url。 – DavidG 2015-03-25 01:19:37