[wp-hackers] Why WP_SITEURL and not $_SERVER['HTTP_HOST']?
Mike Little
wordpress at zed1.com
Tue Mar 30 11:19:25 UTC 2010
On 30 March 2010 11:32, Mike Schinkel <mikeschinkel at newclarity.net> wrote:
>
> 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. :-)
Because a/b may be the site url (and c/d a page name), or it may be a/b/c;
there's no way of knowing until it's manually set up.
There are (perhaps 'were' now ) places in both WP and WPMU that assumed no
port number, and, in WPMU, that assume only http.
Changing the domain name trips up so many people when it seems like it
> shouldn't have to be so hard:
>
>
This I agree with.
> 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));
> }
>
>
I've already written some code like this for a pre-packaged and populated WP
install, and the *first time* it got used it was installed on
http://ip.add.re.ss:5017/wrong-path/ -- my code didn't work at all!
I managed to convince them to accept the path part as pre-defined (otherwise
internal links would break), but they wouldn't budge on the ip address and
port number.
Mike
--
Mike Little
http://zed1.com/
More information about the wp-hackers
mailing list