views:

92

answers:

2

Hi, im creating profile pages based on a subdomains using the wildcard DNS setting.

Problem being, if the subdomain is incorrect, I want it to redirect to the same page but without the subdomain infront ie;

if ( preg_match('/^(www\.)?([^.]+)\.domainname\.co.uk$/', $_SERVER['HTTP_HOST'], $match)) {

$DISPLAY_NAME = $match[2];
$query = "SELECT * FROM `" . ACCOUNT_TABLE . "` WHERE DISPLAY_NAME = '$DISPLAY_NAME' AND ACCOUNT_TYPE = 'premium_account'";
$q = mysql_query( $query, $CON ) or die( "_error_" . mysql_error() );

if( mysql_num_rows( $q ) != 0 ) {



}else{

    mysql_close( $CON );
    header("location: http://www.domainname.co.uk");
    exit;

}

}

I get a browser error: Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

I think its because when using header("location: http://www.domainname.co.uk"); it still puts the sub domain infront i.e. ; header("location: http://www.sub.domainname.co.uk");

Does anyone know how to sort this and/or what is the problem.

Regards,

Phil

A: 

This happens when a webpage redirects you in an endless loop. So probably the page you are referring too is also sparking a referral (or firefox thinks it is).

Mozilla knowledge base explains what you can do about this error.

Thirler
no sure if you understand what you mean. I understand that if I were to have the header `header("location: http://www.sub.domainname.co.uk");` I would give me that error. The fact that im using the header `header("location: http://www.domainname.co.uk");` is different as the if statement would return false and not even get to the redirect part of the script.
Phil Jackson
A: 

Figured this one out. It was due to the browser caching.

header("Expires: Mon, 01 Jul 2003 00:00:00 GMT"); // Past date
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Consitnuously modified
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache"); // NO CACHE
header("location: http://www.domainname.co.uk");

did the trick.

Phil Jackson
Congratulations on fixing the problem.Any chance you can mark your own Answer as being Correct, so the question is closed off?
Lucanos