Skip to content

WP_HOME will not always match SERVER_NAME - #56

Merged
EvanK merged 2 commits into
masterfrom
56-rewrite-urls
Jul 28, 2015
Merged

EvanK merged 2 commits into
masterfrom
56-rewrite-urls

Conversation

@EvanK

@EvanK EvanK commented Jun 24, 2015

Copy link
Copy Markdown
Contributor

While #37 has fixed most url-related issues, it has some lingering side-effects:

  1. Requests to production.$DOMAIN will have all links pointing to $DOMAIN (or www.$DOMAIN, whichever is the canonical)
  2. Requests to $BRANCH.staging.$DOMAIN will have all links pointing to staging.$DOMAIN

There doesn't seem to be a good solution to this, without filtering all content through output buffering.

We could implement this so that output buffering is only turned on when WP_HOME and $_SERVER[SERVER_NAME] aren't equal, but that's still a hack I'd like to avoid..

@ericrasch

Copy link
Copy Markdown
Contributor

I'm seeing this [staging] issue on a current project. Give me anything you want to test and I can put it on here to see if it works.

@EvanK

EvanK commented Jun 23, 2015

Copy link
Copy Markdown
Contributor Author

This seems noteworthy...

On the staging environment, PHP's SERVER_NAME will match the domain on which it was requested, either staging.example.com or somebranchname.staging.example.com.

On the production environment, the SERVER_NAME will always match the canonical server name from apache's vhost (example.com or www.example.com depending on what was configured by the generator), meaning we'd need to check HTTP_HOST for this comparison.

The reason this is worth noting is that SERVER_NAME is significantly more secure as it's provided by the server, where HTTP_HOST is taken directly from the Host: header provided by the client.

Worth noting that this only occurs when Evolution::getHostname() amd $_SERVER[HTTP_HOST] are *not* equal
@EvanK

EvanK commented Jun 24, 2015

Copy link
Copy Markdown
Contributor Author

@ericrasch Implemented a workaround using output buffering (mostly copied from Genesis) that only kicks in when the constructed hostname doesn't match HTTP_HOST.

@EvanK EvanK changed the title WP_HOME will not always match SERVER_NAME [WIP] WP_HOME will not always match SERVER_NAME Jun 24, 2015
@ericrasch

Copy link
Copy Markdown
Contributor

@EvanK you fixed this by modifying the following lines:

        $old_url = '://' . self::getHostname();
        $new_url = '://' . htmlspecialchars($_SERVER['HTTP_HOST']);

@EvanK EvanK changed the title [WIP] WP_HOME will not always match SERVER_NAME [RFC] WP_HOME will not always match SERVER_NAME Jun 25, 2015
@EvanK

EvanK commented Jun 25, 2015

Copy link
Copy Markdown
Contributor Author

I still feel dirty using output buffering + str_replace, but I genuinely don't see a better solution.

The upside, as previously stated, is that it only kicks in when the detected hostname (from Evolution::getHostname) doesn't match HTTP_HOST.

I've also confirmed that varnish uses the same http host during hashing, so we shouldn't see any overlapping caching

@EvanK EvanK changed the title [RFC] WP_HOME will not always match SERVER_NAME WP_HOME will not always match SERVER_NAME Jul 28, 2015
@EvanK

EvanK commented Jul 28, 2015

Copy link
Copy Markdown
Contributor Author

Since I'm doing a minor version bump anyway (for #59), merging this one too

EvanK added a commit that referenced this pull request Jul 28, 2015
WP_HOME will not always match SERVER_NAME
@EvanK
EvanK merged commit c3141a0 into master Jul 28, 2015
@EvanK
EvanK deleted the 56-rewrite-urls branch January 30, 2016 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants