Forum Moderators: open

Message Too Old, No Replies

unwanted URL redirection

Unknown reason for url being redirected

         

Csolution

2:10 pm on Jan 21, 2014 (gmt 0)

10+ Year Member



Hi,

Short back story:

We had a website developed by a company back in 2009, for some reason they made a mistake on the SSL certificate generation where any attempt to reach www.domainname.co.uk would return a security validation on screen (not the case when directing to domainname.co.uk). To resolve this issue, the developers redirected the url to domainname.co.uk whenever a 'www' was used in the url. 3 years later, we have parted ways with that company, they were leaving much to be desired in regards to testing before publishing etc. We've hired a new web developing company to take over the reigns. A few teething problems at first as the previous company didn't provide the documentation (i will forever curse their name). Two weeks ago, we wanted to direct all traffic from another domain name we own, to this server, and discontinue the old domain name over time. We changed the DNS settings with our provider to point to the server (A/IP Address), for both the 'www' and non-www DNS.

Problem:

When ever we try to use the www.newdomainname.co.uk the url redirects to newdomainname.co.uk.

Attempted:

We checked with the DNS provider to make sure everything was setup correctly with our DNS settings, and both 'www' and non-www were being resolved to the IP address as expected.

We checked the web.config file to see if any redirecting was taking place there, there were none.

We checked the HOST file to see if anything in there would be causing the problem, there was nothing.

We checked the IIS to see if any re-directing were taking place, there were none.

We changed the HOST file to redirect to www.newdomainname.co.uk, however; it loaded a blank screen.

We have hit a reinforced brick wall in trying to resolve our problem, neither myself nor the new developer can identify the cause of the re-direct, the DNS provider and Server provider both recommend it being a configuration problem. The next step for the moment is to reach out to anyone who may have an idea as to the problem.

*** The previous developers are unavailable for contact. ***

Can anyone suggest something for us to look for, or to try in order to resolve this problem?

Ocean10000

2:45 pm on Jan 21, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I am assuming this is a dynamic site.

I would look at "Global.asax" code behind and see if there is a redirect in the code there. I would assume it would be in the Application Begin Request event.

if that fails you can do a search for "Response.Redirect" and just check each one, and figure out where they buried it.

Csolution

3:03 pm on Jan 21, 2014 (gmt 0)

10+ Year Member



Thanks for your reply Ocean.

I have looked at the global.asax & asax.cs, and there lies a redirect when encountering the 'www'.

I'll pass this onto my developer to look at now, and update the thread after testing.

dstiles

9:49 pm on Jan 21, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



By switching from your original non-www URL you are running risks. The primary one is search engines, which are probably happy with your old domain and pagenames. Presenting them with a www URL will necessitate a change to their indexes. You would have thought a good SE would accept that www and non-www were identical, but SEs are stupid.

The secondary one is not so critical: other web sites that link to yours. Currently I'm working through a directory and finding a LOT of site links that redirect from the registered link to a new one, and the link-checking tool is throwing up errors for them which, although I do not absoultely need to, I am correcting. Tedious.

All of my sites are designed to work on www and to have non-www redirected to that. The reverse is equally feasible and I would recommend it in your case.

It requires two records to be set up in IIS manager: one for the primary domain (in your case non-www - example.com) which will direct all traffic to the relevant web site home folder. The second record is set up for www addresses (www.example.com) and told to redirect absolutely (301) to the main URL (ie example.com). This record can also include secondary domains obtained, for example, for name protection (eg example.co.uk and www.example.co.uk).

It is always a good idea BEFORE (re)designing a site to work out names and URLs. :)

Csolution

11:45 am on Jan 22, 2014 (gmt 0)

10+ Year Member



We removed the bit of code that we identified as maybe causing the problem, I've attached it below. However, I'm told by my developer that it has caused no change to the redirect of the url after removing the code, from his testing.

public void Application_BeginRequest(object ob, EventArgs e)
{
if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("www."))
{
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("www.", string.Empty));
}
}


We found a number of annotated examples of response.redirect, however none are being used in the code. It seems the old developers tried using response.redirect before changing it to the above.


@dstiles, thanks for your input. We're not heavily dependent on SE at the moment. The website is going through a number of changes, content also, and so the SE would be updating itself when ever it hit our site. We've taken into consideration the impact with the SE, and it's was decided to go for it, as the domain we're changing to is the preferred with the company management.

Also, we have tried your final suggestion, to which my developer has told me has not resolved the problem with the www re-directing to the non-www.

dstiles

9:39 pm on Jan 22, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Fine with the SE decisions. :)

If the two records in IIS manager failed then it wasn't implemented properly. I've been setting these up for years and the only time it fails is when I do something dumb. :)

I assume your developer has full access to the IIS manager? If not the hosting company would need to be involved.

I will qualify the above: I currently use Windows 2003 and all is well but I anticipate the same will work in a few months when I upgrade to 2008 or later.

Ocean10000

3:57 pm on Jan 23, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



By the previous developer using the following.
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("www.", string.Empty));

He has made it so that the browser cached this directive, so even after you remove it from the website code, the browser will remember it.

Try flushing your browser cache or trying it from a different browser which you have not previously visited the site with.

dstiles

9:58 pm on Jan 23, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



An obvious action which I frequently forget myself, even for a less rigorous coding! :)

Csolution

9:51 am on Jan 24, 2014 (gmt 0)

10+ Year Member



Thanks for your replies!

We've flushed the cache after the code change but there was no change.

The developer has full access to IIS.

I have asked him to start from scratch and re-create the IIS records again, to see what happens.

Ocean10000

4:42 pm on Jan 24, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You might also want to check the logs of the website to see which host is being requested, if it even requesting www version first or just going straight to the non-www version, even when the www version is typed into the url bar.

If it skips without even going to the www version first this would indicate it was a browser issue.

Csolution

9:16 am on Jan 28, 2014 (gmt 0)

10+ Year Member



Over a couple of days scratching heads, somehow, the server after an IIS restart started to behave.

The www started to load to screen with content, however, what exactly was changed by my developer i/we do not know exactly.

Needless to say i no longer have my boss bearing down on me regarding this.

Thanks for both of your inputs with my problem!

Ocean10000

4:04 pm on Jan 28, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks for the update.