Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions source/content/server_name-and-server_port.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ Some code relies on `$_SERVER['SERVER_NAME']` and `$_SERVER['SERVER_PORT']` to c

In general, you don't want your code to rely on this, but some extensions (themes, modules, plugins) give you no choice. In that case, you will need to modify the `$_SERVER` variable in your `settings.php` (Drupal) or `wp-config.php` (WordPress) file to ensure the right values are present.

## Use HTTP_HOST Instead of SERVER_NAME
## Use PANTHEON_HOSTNAME Instead of SERVER_NAME

`HTTP_HOST` is generated dynamically based on the current request, while `SERVER_NAME` is static. If the `$_SERVER`variable is set to `'SERVER_NAME'`, the URL generated for a request will be something similar to `https://endpoint05ccd237.chios.panth.io` instead of the intended `https://yourdomain.com`.
`PANTHEON_HOSTNAME` is added in `wp-config-pantheon.php` and constructed from `HTTP_HOST` (if available) or the Pantheon environment if `HTTP_HOST` is unavailable (e.g. in WP-CLI). If the `$_SERVER`variable is set to `'SERVER_NAME'`, the URL generated for a request will be something similar to `https://endpoint05ccd237.chios.panth.io` instead of the intended `https://yourdomain.com`.

Adding the following code will pass the correct value when `'SERVER_NAME'` is used:

```php
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
$_SERVER['SERVER_NAME'] = PANTHEON_HOSTNAME;
```

`PANTHEON_HOSTNAME` can be overridden by defining the constant manually in your `wp-config.php` file before the `wp-config-pantheon.php` file is required as noted in the [`wp-config.php` documentation](/guides/php/wp-config-php#how-can-i-override-the-default-pantheon_hostname-value).

While this fix does correct symptoms such as undesirable URLs, we recommended replacing all instances of `'SERVER_NAME'` with `'HTTP_HOST'` directly (e.g. [`WP_HOME` and `WP_SITE`](https://github.com/pantheon-systems/WordPress/blob/default/wp-config-pantheon.php#L52) for WordPress).

<Alert title="Note" type="info">
Expand Down
6 changes: 3 additions & 3 deletions source/content/wordpress-known-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ ___
**Solution:** Add the following to `wp-config.php`:

```php:title=wp-config.php
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
$_SERVER['SERVER_NAME'] = PANTHEON_HOSTNAME;

if (isset($_ENV['PANTHEON_ENVIRONMENT'])) {
if (isset($_SERVER['HTTP_USER_AGENT_HTTPS']) && $_SERVER['HTTP_USER_AGENT_HTTPS'] === 'ON') {
Expand Down Expand Up @@ -860,7 +860,7 @@ ___
// server name and not the current hostname, as a
// result, Redirection's "URL and server"-based
// redirects never match.
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
$_SERVER['SERVER_NAME'] = PANTHEON_HOSTNAME;
```

Visit the [SERVER_NAME and SERVER_PORT on Pantheon](/server_name-and-server_port) doc for more information about how to use `HTTP_Host` on Pantheon.
Expand Down Expand Up @@ -930,7 +930,7 @@ The plugin generates the site's URL using `$_SERVER['SERVER_NAME']` instead of `
**Solution:** Add the following line to `wp-config.php`:

```php:title=wp-config.php
$_SERVER['SERVER_NAME'] = $_SERVER['HTTP_HOST'];
$_SERVER['SERVER_NAME'] = PANTHEON_HOSTNAME;
```

___
Expand Down