Primary Domains
Learn more about choosing your primary domain.
This section provides information on how to choose and configure your primary domain.
Choose Primary Domain
Pantheon uses the term primary domain to refer to a single domain used to serve all traffic from a site. For example, configuring www.example.com
as the primary domain means that requests to example.com
(or any other custom domain connected to the environment) all get redirected to www.example.com
. This assumes that you have added both example.com
and www.example.com
to the Site Dashboard.
Redirecting all traffic to a primary domain is a best practice for SEO since it avoids duplicate content. It also prevents session strangeness, where a user can be logged in to one domain but logged out of other domains at the same time, and it can make it easier to measure and monitor website traffic.
Choose a primary domain from the dropdown at the bottom of Domains / HTTPS:
Redirects cannot be managed via .htaccess
, which is ignored on our platform. For details, refer to Configure Redirects.
Set a Primary Domain via the Dashboard
With a Primary Domain set at the platform level, all other domains (except the platform domain) will be pointed to your Primary domain at the root level. If you want to redirect secondary domains to specific pages on your site (for example, olddomain.com
to newdomain.com/old-landing-page
), do not set a Primary Domain. Instead use PHP redirects.
Navigate to the environment you want to set a primary domain for (typically Test or Live), and then select Domains / HTTPS.
Ensure that all domains have been added and are listed.
Navigate to the Choose Primary Domain section, select the domain to which traffic should be redirected, and then click Save Configuration.
You will only see the primary redirect option when you have two or more custom domains attached to your environment. If you want to redirect a single platform domain, you must do the primary redirect via PHP. For example, live-mysite.pantheonsite.io
to www.example.com
Set a Primary Domain with Terminus
Install or upgrade to the latest version of Terminus.
Use Terminus to add the primary domain. In this example, replace:
my-site
with your site namelive
if you'd like to set it for a different environmentwww.example.com
with your primary domain
terminus domain:primary:add my-site.live www.example.com
Update or Remove Primary Domain
Update the Primary Domain using either method provided in the previous section.
Remove an existing selection for the Primary Domain on any environment using Terminus:
terminus domain:primary:remove my-site.live
Replace my-site
with your site name, and live
with the environment you're removing a primary domain from.
Verify
You can confirm that the Primary Domain has been removed with cURL pointed at one of your other custom domains, which would previously have been redirected:
curl -I https://example.com
HTTP/2 301
retry-after: 0
server: Pantheon
location: https://www.example.com/
x-pantheon-redirect: primary-domain-policy-docdate: Wed, 05 Feb 2020 16:43:21 GMT
x-served-by: cache-mdw17355-MDW
x-cache: HIT
x-cache-hits: 0
x-timer: S1580921002.586800,VS0,VE1
age: 0
accept-ranges: bytes
via: 1.1 varnish
content-length: 0
The presence of x-pantheon-redirect: primary-domain-policy-doc
indicates that the domain is still being pointed at the former Primary Domain. Contact support if this value persists.
Redirect to HTTPS
It's a best practice for SEO and security to standardize all traffic on HTTPS and choose a primary domain. Configure redirects to the primary domain with HTTPS in pantheon.yml
Redirect with PHP
If your site configuration prevents you from setting the primary domain from the platform level, you can use PHP redirects:
PHP Redirection
Add the following to wp-config.php
, usually placed above /* That's all, stop editing! Happy Pressing. */
. Don't forget to replace www.example.com
:
if (isset($_ENV['PANTHEON_ENVIRONMENT']) && php_sapi_name() != 'cli') {
// Redirect to https://$primary_domain in the Live environment
if ($_ENV['PANTHEON_ENVIRONMENT'] === 'live') {
// Replace www.example.com with your registered domain name.
$primary_domain = 'www.example.com';
}
else {
// Redirect to HTTPS on every Pantheon environment.
$primary_domain = $_SERVER['HTTP_HOST'];
}
$requires_redirect = false;
// Ensure the site is being served from the primary domain.
if ($_SERVER['HTTP_HOST'] != $primary_domain) {
$requires_redirect = true;
}
// If you're not using HSTS in the pantheon.yml file, uncomment this next block.
// if (!isset($_SERVER['HTTP_USER_AGENT_HTTPS'])
// || $_SERVER['HTTP_USER_AGENT_HTTPS'] != 'ON') {
// $requires_redirect = true;
// }
if ($requires_redirect === true) {
// Name transaction "redirect" in New Relic for improved reporting (optional).
if (extension_loaded('newrelic')) {
newrelic_name_transaction("redirect");
}
header('HTTP/1.0 301 Moved Permanently');
header('Location: https://'. $primary_domain . $_SERVER['REQUEST_URI']);
exit();
}
}
WordPress users should also run a search and replace to update any references to the platform domain.
Add the following to the end of your settings.php
file (replace www.example.com
):
if (isset($_ENV['PANTHEON_ENVIRONMENT']) && php_sapi_name() != 'cli') {
// Redirect to https://$primary_domain in the Live environment
if ($_ENV['PANTHEON_ENVIRONMENT'] === 'live') {
// Replace www.example.com with your registered domain name.
$primary_domain = 'www.example.com';
}
else {
// Redirect to HTTPS on every Pantheon environment.
$primary_domain = $_SERVER['HTTP_HOST'];
}
$requires_redirect = false;
// Ensure the site is being served from the primary domain.
if ($_SERVER['HTTP_HOST'] != $primary_domain) {
$requires_redirect = true;
}
// If you're not using HSTS in the pantheon.yml file, uncomment this next block.
// if (!isset($_SERVER['HTTP_USER_AGENT_HTTPS'])
// || $_SERVER['HTTP_USER_AGENT_HTTPS'] != 'ON') {
// $requires_redirect = true;
// }
if ($requires_redirect === true) {
// Name transaction "redirect" in New Relic for improved reporting (optional).
if (extension_loaded('newrelic')) {
newrelic_name_transaction("redirect");
}
header('HTTP/1.0 301 Moved Permanently');
header('Location: https://'. $primary_domain . $_SERVER['REQUEST_URI']);
exit();
}
}