如何在webconfig或websitepanel中将example.com映射到www.example.com

时间:2015-07-08 14:56:23

标签: asp.net-mvc redirect url-rewriting web-config

我使用ASP.net MVC并且我在arvixe中使用websitepanel和我的托管现在我需要使用www.example.com打开我的网站

现在我的网站打开了2个网址:

  • www.example.com
  • example.com

我需要只用一个网址打开它:www.example.com这样 当用户输入example.com作为网址时,它会转到www.example.com

我如何在web.config或websitepanel配置中执行此操作?

我无法访问IIS。

1 个答案:

答案 0 :(得分:0)

Hopefully the same will still apply to your setup but I add the following to the live web.config. It will ensure a 301 redirect from non-www to www prefixed domain:

<system.webServer>
    <rewrite>
       <rules>
         <clear />
         <rule name="WWW Rewrite" enabled="true">
           <match url="(.*)" />
           <conditions>
             <add input="{HTTP_HOST}" negate="true" pattern="^www\." />
           </conditions>
           <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
         </rule>
      </rules>
    </rewrite>
    ...
  </system.webServer>