【问题标题】:Configure redirect asp.net/iis7配置重定向 asp.net/iis7
【发布时间】:2011-12-12 13:02:26
【问题描述】:

当用户输入http://example.comhttp://www.example.com 时,我有一个网站会打开。

我需要将服务器或应用程序配置为在访问 example.com 时永久重定向到 www.example.com。

非常重要的是保留路径,所以如果exam​​ple.com/path/page.aspx?p=1,则应该重定向到www.example.com/path/page.aspx?p= 1.

谢谢!

【问题讨论】:

    标签: asp.net iis-7


    【解决方案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>
    

    【讨论】:

    • 不起作用,但还是谢谢!我会尝试弄清楚如何保留协议..谢谢!
    • 这只是一个例子。也许这个链接可以帮助你更好地理解:10 URL Rewriting Tips and Tricks
    【解决方案2】:

    URL Rewrite module 应该完全满足您的需求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-25
      • 2012-02-24
      • 2010-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-12
      • 2012-03-31
      相关资源
      最近更新 更多