2017-02-11 82 views
-1

我有任何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

回答

0

這需要在web.config中完成,而不是.htaccess。有一個類似的問題,回覆很好here

0

您可以使用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> 
0

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