想要打开我的网站www

问题描述:

我有任何asp.net mvc网站,我想打开它作为www.example.com而不是example.com。我想将每个使用example.com的用户重定向到www.example.com。我这样做的原因是为了保持cookie。由于目前有两种不同的饼干套件,其中一套适用于www.example.com,另一套适用于example.com。我怎样才能做到这一点?想要打开我的网站www

+0

我认为你需要考虑.htaccess重定向 – bwoogie

+0

为什么不为'.example.com'设置cookie? – mrun

这需要在web.config中完成,而不是.htaccess。有一个类似的问题,回复很好here

您可以使用IIS URL Rewrite Module。但是它默认情况下并未安装在服务器上。安装后,您可以在网站的Web.Config文件中创建规则。

<system.webServer> 
    <rewrite> 
    <rules> 
     <rule name="Redirect to www" stopProcessing="true"> 
     <match url=".*" ignoreCase="true" /> 
     <conditions> 
      <add input="{HTTP_HOST}" pattern="^traindb.nl" /> 
     </conditions> 
     <action type="Redirect" url="http://www.traindb.nl/{R:0}" redirectType="Permanent" /> 
     </rule> 
    </rules> 
    </rewrite> 
</system.webServer> 

您可以在DNS或甚至IIS设置中从example.com - > www.example.com配置重定向。