如何删除www。 ASP.NET MVC中的前缀 [英] How to remove the www. prefix in ASP.NET MVC

查看:90
本文介绍了如何删除www。 ASP.NET MVC中的前缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何删除www。来自传入的请求?我需要设置301重定向还是仅重写路径?无论哪种方式,什么是最好的方法?

How do I remove the www. from incoming requests? Do I need to setup a 301 redirect or simply just rewrite the path? Either way, what's the best way to do it?

谢谢!

推荐答案

我认为使用IIS的URL重写模块更合适。

I believe it would be more appropriate to do that with IIS' URL rewriting module.

如果您可以使用IIS的管理工具,则可以设置一个GUI您网站设置的 IIS部分中的重新编写规则。如果从那里(在右列菜单中)选择添加规则...,请在SEO部分中选择规范域名规则,以几乎完全自动化地设置规则。

If you have access to IIS' management tool, there's a GUI to set up rewrite rules, in the "IIS" section of your site's settings. If you choose "Add Rule(s)..." from there (in the right column menu), choose the "Canonical domain name" rule in the SEO section to almost completely automate getting the rule set up.

如果没有,重写规则将在您的web.config中如下所示:

If not, the rewrite rule would look like this in your web.config:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="CanonicalHostNameRule1">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^yourdomain\.com$" negate="true" />
                </conditions>
                <action type="Redirect" url="http://yourdomain.com/{R:1}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

这篇关于如何删除www。 ASP.NET MVC中的前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆