[wp-hackers] Why WP_SITEURL and not $_SERVER['HTTP_HOST']?

Mike Schinkel mikeschinkel at newclarity.net
Tue Mar 30 10:32:42 UTC 2010

On Mar 30, 2010, at 5:11 AM, Mike Little wrote:
> On 30 March 2010 09:03, Mike Schinkel <mikeschinkel at newclarity.net> wrote:
>> P.S. Hmm.  If we need a constant, is there a reason why WP_SITEURL is not
>> just set in wp-config.php based on the value of $_SERVER['HTTP_HOST']?
> You also have to take into account that $_SERVER['HTTP_HOST'] does not
> contain the schema, the port number, or any path part. The path part in
> particular is a problem even if you try to use the various other
> $_SERVER variables. If the very first hit to a site is http://domain.com/a/b/c/d/,
> which part of that is site url?


The follow up is: Why then don't we just store "a/b/c/d/" to WP_SITEPATH and you get the domain from $_SERVER['HTTP_HOST'] and the port from $_SERVER['SERVER_PORT']?  (we can hardcode the "http(s)", that's okay. :-)  Changing the domain name trips up so many people when it seems like it shouldn't have to be so hard:


Anyway, I'm not going to take on a fight to get it changed at this point, I have just been trying to understand the pitfalls of using $_SERVER['HTTP_HOST']  to *recognize* that the site has loaded via a domain that isn't what it is configured to be.  IOW, if I were to run this code as early as I can in the bootstrap, what problems might it cause?:

	$old_domain = get_option('siteurl');
	$new_domain = $_SERVER['HTTP_HOST'];
	if ($old_domain != $new_domain) {
		$valid_domains = array('dev.examples.com','test.example.com','stage.example.com','www.example.com');
		if (in_array($new_domain,$valid_domains) && in_array($old_domain,$valid_domains)) 

Thanks in advance.


More information about the wp-hackers mailing list