简体   繁体   English

将非www网址重定向到www

[英]Redirecting non - www urls to www

Currently both http://example.com and http://www.example.com works fine. 目前http://example.comhttp://www.example.com运行良好。 However we need to make all http://example.com urls to be redirected to http://www.example.com . 但是,我们需要将所有http://example.com网址重定向到http://www.example.com

The site is an ASP.net MVC4 website. 该网站是一个ASP.net MVC4网站。 To get it done I have added the following web.config entry under System.webserver. 为了完成它,我在System.webserver下添加了以下web.config条目。

<httpRedirect enabled="true" destination="http://www.example.com" />

However it is resulted in a redirect loop. 但是它导致了重定向循环。 Can you please help me get this done. 能帮我完成这件事吗?

Try Adding this to web.config. 尝试将此添加到web.config。 There must be rewrite module installed in your IIS. 您的IIS中必须安装重写模块 Read this Article for better explanation. 阅读 文章为更好的解释。

<rewrite>
    <rules>
        <rule name="Redirect domain.com to www" patternSyntax="Wildcard" stopProcessing="true">
            <match url="*" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="domain.com" />
            </conditions>
            <action type="Redirect" url="http://www.domain.com/{R:0}" />
        </rule>
    </rules>
</rewrite>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM