2011-12-12 86 views
1

我有一個網站,當用戶輸入或者http://example.comhttp://www.example.com打開。配置重定向asp.net/iis7

我需要配置服務器或應用程序與永久重定向到www.example.com重定向example.com被訪問時。

什麼是非常重要的是,該路徑被保留,所以如果exam​​ple.com/path/page.aspx?p=1,重定向應做www.example.com/path/page.aspx?p = 1。

謝謝!

回答

1

使用URL Rewrite你可以通過在你的web.config中添加配置做到這一點。你也需要在你的IIS中安裝這個模塊。這裏是一個例子,沒有完全測試:

<system.webserver> 
<rewrite> 
     <rules>    
      <rule name="Redirecting" stopProcessing="true"> 
       <match url="(.*)" /> 
       <conditions> 
        <add input="{HTTP}" pattern="^(http://)?example.com" ignoreCase="true" /> 
       </conditions> 
       <action type="Redirect" redirectType="Permanent" url="http://www.example.com/{R:1}" /> 
      </rule> 
     </rules> 
    </rewrite> 
</system.webserver> 
+0

不起作用,但無論如何感謝!我會試着弄清楚如何保存協議..謝謝! – user1082693

+0

這只是一個例子。也許這個鏈接可以幫助你更好地理解:[10 URL重寫提示和技巧](http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/) –