2011-12-12 110 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/) –