配置重定向 asp.net/iis7

发布于 2024-12-21 00:49:35 字数 340 浏览 1 评论 0原文

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

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

非常重要的是保留路径,因此如果 example.com/path/page.aspx?p=1,则应重定向到 www.example.com/path/page.aspx?p=1。

谢谢!

I have a website that opens when the user enters either http://example.com or http://www.example.com.

I need to configure the server or the app to redirect with a permanent redirect to www.example.com when example.com is accessed.

What is very important is that the path is preserved, so if example.com/path/page.aspx?p=1, the redirect should be done to www.example.com/path/page.aspx?p=1.

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巷雨优美回忆 2024-12-28 00:49:35

使用 URL 重写,您可以通过在 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>

Using the URL Rewrite you can do this by adding a configuration in you web.config. You need to install this module in your IIS as well. Here is an example, not fully tested:

<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>
稍尽春風 2024-12-28 00:49:35

URL 重写模块 应该完全满足您的需要。

The URL Rewrite module should do exactly what you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文