Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically set WP_HOME and WP_SITEURL #224

Closed
garand opened this issue Dec 13, 2015 · 5 comments
Closed

Dynamically set WP_HOME and WP_SITEURL #224

garand opened this issue Dec 13, 2015 · 5 comments

Comments

@garand
Copy link

garand commented Dec 13, 2015

Have you considered setting the WP_HOME and WP_SITEURL's dynamically?

For instance, adding the following to the config file and removing the corresponding entries from the .env file.

define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/wp');

This would allow for an install that isn't dependent on a consistent hostname and making local development a bit easier. In my case, I run my local sites with the built-in PHP web server with a random port number each time to prevent conflicts from multiple instances running.

@QWp6t
Copy link
Member

QWp6t commented Dec 13, 2015

Nah, we won't be adding this to bedrock, but you can do this in your .env file no prob.

Add this to your .env file...

WP_HOME="http://${HTTP_HOST}"
WP_SITEURL="${WP_HOME}/wp"

@QWp6t QWp6t closed this as completed Dec 13, 2015
@garand
Copy link
Author

garand commented Dec 13, 2015

Oh nice. Didn't know I could do it that way.

Curious on why you're against it though? Anything I'm missing that it breaks?

@QWp6t
Copy link
Member

QWp6t commented Dec 13, 2015

In production, it can result in duplicate content "penalties" since WP_HOME constant is used to determine canonical URLs, e.g., both www and non-www URLs to a post will be "canonical," and if you have any aliases for your domain, then they're canonical as well.

Plus I suspect it would take a giant shit all over multisite setups with subdomains. lol

@kalenjohnson
Copy link
Contributor

What about HTTPS? Also, while it might be ok for development, it's probably not a great idea for production. You wouldn't want to assume that PHP's global vars are always 100% correct, I wouldn't want to rely on it for something so integral when it's an easy fix to set it as an env var.

And unfortunately, your case is a little edge case, it's the first time I've heard of someone using PHP's built in server for any extended period of time. Most people use Vagrant or some other local server set up

@garand
Copy link
Author

garand commented Dec 13, 2015

Gotcha, thanks for the added insight! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants