The issue is that you have a website with the domain name your-domain.com. However, due to certain requirements, you need to point multiple different domains to this one website, such as your-domain.com.au, your-domain.com.uk, etc. So, how do we point multiple domains to one website running on WordPress?
We need to address three issues:
- Parked domain (Aliases) on the hosting where the main site is running, ensuring they point to the correct directory of the main site (typically /public_html).
- Redirect WP_SITEURL and WP_HOME to the domain that the user is accessing.
- Set up SEO to avoid Google flagging multiple sites with duplicate content.
Redirect WP_SITEURL and WP_HOME
For example, when you add the parked domain (Aliases) your-domain.com.au to your-domain.com, by default, when accessing your-domain.com.au, the browser will automatically redirect to the main domain your-domain.com. Therefore, we need to add the following code to the wp-config.php file so that when users access any of the domains, it will stay on that domain, and the links to posts and pages will remain on the domain the user accessed.
Add the following code to the wp-config.php file:
// Multi Domain for a site
define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
Once you add this code, most of the work is done. You will now be able to access the parked domains (Aliases) without any issues.
However, there’s still one problem: when multiple domains point to the same website, it can negatively affect your SEO. Google may identify this as duplicate content, and you could lose your rankings in search results. Don’t worry, though; I have a solution for you.
SEO Setup to Avoid Ranking Loss on Google
If you are using the Yoast SEO plugin, add the following code to the functions.php file in your theme. This will redirect all canonical traffic to the main site and prevent Google from flagging duplicate content when using multiple parked domains (Aliases).
Add this code to the functions.php file:
// canonical - old domain to new domain
add_filter('wpseo_canonical', 'swpseo_canonical_domain_replace');
function swpseo_canonical_domain_replace($url){
$domain = 'your-domain.com'; // Change this to your main site, for example, your-domain.com
$parsed = parse_url(home_url());
$current_site_domain = $parsed['host'];
return str_replace($current_site_domain, $domain, $url);
}
If you are using the All in One SEO plugin, add the following code to functions.php:
// canonical - old domain to new domain
add_filter('aioseo_canonical_url', 'aioseo_canonical_domain_replace');
function aioseo_canonical_domain_replace($url){
$domain = 'your-domain.com'; // Change this to your main site, for example, your-domain.com
$parsed = parse_url(home_url());
$current_site_domain = $parsed['host'];
return str_replace($current_site_domain, $domain, $url);
}
Fix Font Errors When Running with Additional Domains
Once you’ve set up multiple domains to run on a single WordPress source, you might encounter issues with fonts not loading, such as icon fonts not displaying, as shown below:
Error:
“Access to Font at … from origin … has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin … is therefore not allowed access.”
To fix this issue, copy the following code into the .htaccess file:
<IfModule mod_headers.c>
<FilesMatch "\.(ttf|ttc|otf|eot|woff|woff2|font.css|css|js)$">
Header set Access-Control-Allow-Origin "*"
</FilesMatch>
</IfModule>