[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?
Thanks.
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:
http://codex.wordpress.org/Changing_The_Site_URL
http://www.mydigitallife.info/2007/10/01/how-to-move-wordpress-blog-to-new-domain-or-location/
http://yoast.com/move-wordpress-blog-domain-10-steps/
http://chrisschuld.com/2009/10/moving-a-wordpress-install-from-one-domain-a-to-another-domain-b/
http://www.venukb.com/2008/05/05/moving-wordpress-to-another-domain/
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))
do_action('switch_domain',array('old'=>$old_domain,'new'=>$new_domain));
}
Thanks in advance.
-Mike
More information about the wp-hackers
mailing list