PHP - dynamic page via subdomain

Posted by Phil Jackson on Stack Overflow See other posts from Stack Overflow or by Phil Jackson
Published on 2010-04-14T09:23:18Z Indexed on 2010/04/14 9:32 UTC
Read the original article Hit count: 209

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about php

Related posts about redirect