Welcome to WebmasterWorld Guest from 3.84.130.252

Forum Moderators: ocean10000

non-www to www Redirects

     
5:09 pm on Dec 21, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 12, 2006
posts:1309
votes: 0


I'm having a problem with redirecting non-www to www on a Windows server (IIS 7.5). The control panel features are Parallels Panel (Plesk 11.5). I recently installed an SSL cert and my goal is to redirect both non-www (http://example.com) and www (http://www.example.com) to HTTPS (https://www.example.com).

Problem
To redirect, I am using a web.config file in my root directory with the following rewrite rules:
<rewrite>
<rules>
<rule name="Redirect to https" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" negate="false" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>

This works fine if I type www.example.com into a browser. However, I get stuck in a redirect loop if I type example.com into the browser. Additionally, I have tried several input conditions in my web.config file like:
<add input="{HTTP_HOST}" pattern="example\.com" />
But, that did not work. I also tried replacing the action URL {HTTP_HOST} setting with www.example.com to force everything to www, but that did not work either. I also tried removing the web.config file and added my own redirects to the top of my web pages. No luck. Nothing seems to work when typing example.com into the browser.

Parallels Panel (Plesk) Settings
In Plesk, I have changed the “Preferred Domain” feature to “None,” which goes against common wisdom since search engines will treat both URL versions (www and non-www) as URLs of different sites. However, this is solved by using a web.config file to force redirects, right?

Web Server Settings
This is an old site, so my default document is “index.asp"; this probably does not matter though.

Question:
Has anyone had similar experiences with browser redirect issues using a web.config under IIS, or do you have any suggestions?

My best guess is, there is a default configuration on the server that I am unaware of. The IIS Rewrite module is installed and working properly, and if I turn on or off the default document (index.asp), it still does not work. I tried communicating with the host provider, but their response was generic, and they did not want to provide specifics on URL redirects.
5:18 pm on Dec 21, 2018 (gmt 0)

Preferred Member

10+ Year Member Top Contributors Of The Month

joined:Feb 5, 2004
posts: 573
votes: 68


This works for me:


<!-- Redirect to https and www version -->
<rule name="Redirect non-www to www" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www\." negate="true" />
</conditions>
<action type="Redirect" url="https://www.{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>
7:46 pm on Dec 21, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 12, 2006
posts:1309
votes: 0


Thanks for the info JesterMagic. I just tried your web.config rule and it doesn't work for me. I've tried a similar configuration before. I'm beginning to think there is a default redirect somewhere, but I have no idea where.
8:15 pm on Dec 21, 2018 (gmt 0)

Preferred Member

10+ Year Member Top Contributors Of The Month

joined:Feb 5, 2004
posts: 573
votes: 68


Sorry I can't be more help. I have direct access to my Microsoft Windows Server 2012 so I don't use a control panel and don't know of the limitations behind it.

Have you tried using some tools to get better insight on what may be happening? I used them to double check my redirects were working properly. Search for Redirect Detective and Redirect Check
8:33 pm on Dec 21, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 12, 2006
posts:1309
votes: 0


Yep--one of the headaches of using a shared server with a hosting provider. I would probably have better luck with a VPS or dedicated server. I haven't tried those tools, but I will certainly look them up. Thanks.
10:24 pm on Dec 21, 2018 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 12, 2006
posts:1309
votes: 0


Update: Problem Solved

The issue was a caching problem on the server. I finally got the hosting provider to look deeper into the redirect loop. Apparently, a cleared cache fixed the problem. All of the web.config settings I tried (including the one suggested by JesterMagic) worked fine; it was a caching issue and once they cleared the cached, the redirect no longer looped.
3:13 pm on Dec 22, 2018 (gmt 0)

Preferred Member

10+ Year Member Top Contributors Of The Month

joined:Feb 5, 2004
posts: 573
votes: 68


Glad you figured it out. I didn't realize redirects could be cached by IIS.
9:18 pm on Dec 22, 2018 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11684
votes: 205


from the HTTP Protocol [w3.org]:
This response is cacheable unless indicated otherwise.
2:33 pm on Dec 23, 2018 (gmt 0)

Senior Member from GB 

WebmasterWorld Senior Member dstiles is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:May 14, 2008
posts:3244
votes: 18


My solution, from years ago, is to have two entries in IIS Manager, one for the www (real) domain and one for the non-ww and any me-too domains. To make this work in https you have to redirect the second record to the primary domain and under Basic Settings set the physical path of the non-www domains to some folder (eg /redirection) above site-root.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members