简体   繁体   中英

Redirecting non - www urls to www

Currently both http://example.com and http://www.example.com works fine. However we need to make all http://example.com urls to be redirected to http://www.example.com .

The site is an ASP.net MVC4 website. To get it done I have added the following web.config entry under System.webserver.

<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. There must be rewrite module installed in your 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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