Solved

Redirect causes infinite loop

Posted on 2008-06-18
19
3,282 Views
Last Modified: 2012-05-05
We want to be able to redirect people who go to example.com to www.example.com.  I followed the instructions here:
http://www.xoc.net/works/tips/domain.asp

But this causes an infinite redirect.  Both example.com & www.example.com are setup to point to the same location on the server.  When I use the HTTP redirect to redirect example.com to www.example.com, I get a message in Firefox that the page will never stop loading.  In IE, the page never stops loading (go figure).  When I look at the properties of www.example.com, it is set to redirect also, even though I only specified the site example.com to do this.  After unchecking both sites and ensuring that only example.com is checked to redirect, www.example.com is automatically updated.

What is going on?
0
Comment
Question by:eohns
  • 10
  • 9
19 Comments
 
LVL 58

Expert Comment

by:tigermatt
ID: 21815180
Have you actually created separate sites for them in IIS? If you haven't, you will see this sort of behaviour.
0
 

Author Comment

by:eohns
ID: 21815205
Yes, there are two sites, example.com and www.example.com.  They both point to the same physical location on the server but are separate sites in IIS.  When I expand the "Sites" folder in the IIS manager, I see example.com and www.example.com.  Changing the HTTP Redirect of example.com also changes it on www.example.com.  They do share an application pool because I do not want example.com to have it's own set of resources.  However, giving www.example.com it's own application pool as a test did not resolve the problem.
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 21815238
What about if you completely remove the application pool from the example.com site?

Also I assume you have correctly configure host headers so the sites are listening on the correct domain - no spelling mistakes etc.!
0
 

Author Comment

by:eohns
ID: 21815283
I'm not sure what you mean by correctly configure host headers.  I just added the two sites and used the IIS manager's HTTP Redirect function to specify a 301 Redirect from example.com to www.example.com.  I can only assume that IIS is passing the header information along properly, but www.example.com is spelled correctly in the HTTP Redirect function if that's what you're suggesting.

Also, I do not know how to remove an Application Pool.  When You view the Basic Settings of the website where Application Pool can be selected, there is no option for no pool, just the standard pools that have been defined plus DefaultAppPool.

As I mentioned, the source of the problem is that when I use IIS's HTTP Redirect on the site example.com, the site www.example.com is also set to do an HTTP redirect (to itself), and this causes an infinite loop.
0
 

Author Comment

by:eohns
ID: 21815305
In followup, when I use IIS's HTTP Redirect, it just configures the web.config for the site, which exists in the site's directory (which is the same for both as per the redirect instructions).  Consequently, that is probably why the other site is also set to redirect, they are both using the same web.config.  I am going to try to set the example.com to a different directory and see if that helps or makes things worse.
0
 

Author Comment

by:eohns
ID: 21815319
That solved the problem, though I don't like this solution.  This requires a useless directory on the server to point example.com to--does anyone have a better solution on how to achieve the same functionality?  I don't think something as simple as combining www and non-www should be this complicated.
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 21815334
I think the problem you've got is that both sites are listening without any form of separation between the two. On each site in IIS, open it up and follow the info in the latter part of http://www.visualwin.com/host-header/ to add the correct host header for that site. For example, on the redirect site, you'd use example.com, and on the main site, you'd configure the header as www.example.com.

That means the sites will only respond to requests pointed at their own host header.
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 21815348
>>> "That solved the problem"
Which method are you talking about here?
0
 

Author Comment

by:eohns
ID: 21815375
Pointing the physical location of example.com to a different location than that of www.example.com.  This allows each site to use a different web.config, therefore when I add a HTTP Redirect to example.com, it does not update the web.config used for www.example.com.  I just don't feel that this is a good solution because it requires a physical folder to exist for a website that will never be used.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:eohns
ID: 21815388
Both sites are configured with their respective hostnames in IIS.  The site you gave me is for IIS 5, I am using IIS 6 but I was able to determine the updated notation for IIS6.  They are called Site Bindings.  The Host Name binding for example.com is example.com and for www.example.com it is www.example.com.
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 21815467
Are you sure you're using IIS 6? The site I gave you is for IIS 6, which is what you will find on Windows Server 2003. If you're not actually using that version of IIS (let me know what operating system it is), then it is going to be a different procedure, but as per the question title, you say you have IIS 6 and the link is for IIS 6.
0
 

Author Comment

by:eohns
ID: 21815502
I apologize, I was thinking the new IIS was version 6, it is version 7, we have Windows Server 2008.
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 21816339
I'm just building a Virtual Machine of Server 2008 to check this out in a test environment. I'll get back to you as soon as I can.
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 21877919
This one hasn't come up for me yet in a VM - I've set up a redirect using two sites just fine.
Have you found any more yourself?
0
 

Author Comment

by:eohns
ID: 21879165
Every site I configure suffers from this problem.  It occurs when you have two sites that point to the same physical location on the server.  When they both point to the same physical location, they use the same web.config.  The web.config handles redirect, so using the IIS administration interface to enable redirect from one site to another will also set the latter to do redirect (because all IIS does is update the web.config, which both sites use) and therefore causes an infinite loop when accessing the latter site.  I always setup a www.example.com and an example.com and redirect example.com to www.example.com.  If I point both of these sites to the same physical location, then setting the redirection on example.com also sets it on www.example.com.  The only way I currently know to solve this is to not have them both at the same physical location, which I achieve by having a www folder in the site name folder under C:\inetpub.  The physical location for www.example.cmo is C:\inetpub\example.com\www and the physical location for example.com is C:\inetpub\example.com.  This sets the web.config for example.com in the root site directory and the web.config for www.example.com in the www directory.  I feel this is an inadequate solution as it shouldn't matter where example.com is physically located because the directory is never served due to the redirect.
0
 
LVL 58

Accepted Solution

by:
tigermatt earned 500 total points
ID: 21881390
Just tried it in my virtualised environment and I am now getting the same behaviour as you when they are in the same directory. There is no way around this. You're going to need to use separate directories, at least in the mean time until some sort of fix is released.
0
 

Author Comment

by:eohns
ID: 21920256
Thanks for looking into it for me.  I'll give you the points anyway because you put forth some effort.  It's a bit of a pain in the behind, but I'll live with it for now.
0
 

Author Closing Comment

by:eohns
ID: 31468493
I can't really consider it complete because it's a bug we can't do anything for.
0
 
LVL 58

Expert Comment

by:tigermatt
ID: 21920281
Thanks anyway, and sorry I wasn't able to track the issue down... it's probably just one of those bugs or design faults which you come across from time to time! :-)
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Join & Write a Comment

A procedure for exporting installed hotfix details of remote computers using powershell
A safe way to clean winsxs folder from your windows server 2008 R2 editions
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now