我想所有的WWW流量重定向到非www交通asp.net的MVC:如何將非WWW重定向到www反之亦然
我已經複製到我的web.config這
<system.webServer>/<rewrite>/<rules>
<rule name="Remove WWW prefix" >
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.domain\.com" />
</conditions>
<action type="Redirect" url="http://domain.com/{R:1}"
redirectType="Permanent" />
</rule>
每這篇文章
How to redirect with "www" URL's to without "www" URL's or vice-versa?
,但我得到了500內部服務器錯誤。
這種方法在MVC中工作嗎?你的方式是我如何在Web窗體中完成它,但我認爲MVC路由框架的處理方式不同。 – 2010-07-07 17:58:37
我採取了非常類似的方法。請參閱http://stackoverflow.com/questions/2175975/asp-net-mvc-301-redirect-from-www-domain-com-to-domain-com – spender 2010-07-07 18:06:17
@rockinthesixstring:它在MVC中起作用。它在很早的時候就開始了,所以MVC或者WebForms是否會在之後處理請求並不重要。 – 2010-07-07 18:32:10