← Back to the blog section Open archive

Article

Using Two Domains with a Single Self-Hosted WordPress Site

If you run a self-hosted WordPress site, the usual setup assumes one primary domain. That is perfectly fine for most projects, but sometimes you want one installation to answer to two different domains without forcing a redirect.

A typical example looks like this: the first domain is already connected to your hosting account and webspace, while the second domain is managed somewhere else, such as Cloudflare. In that case, the goal is not to move the site, but to let both domains work natively with the same WordPress installation.

Here is the clean way to set that up.

First, understand the WordPress URL settings

In a normal single-site setup, WordPress uses two important URL settings:

  • Site Address (URL): the address visitors type into the browser
  • WordPress Address (URL): the location of the WordPress core files

This matters because the standard WordPress configuration expects one value for each. If you hardcode only one domain, WordPress will naturally treat that domain as canonical and may send users, assets, or internal links back to it.

That is why a dual-domain setup needs a slightly more dynamic configuration.

Step 1: Point the second domain to the same server

The first requirement is simple: both domains must resolve to the same origin server.

If the second domain is managed externally, for example in Cloudflare, create DNS records that point to the IP address of your hosting account.

In practice, that usually means:

  • an A record for the root domain
  • optionally a CNAME or additional record for www

If you use Cloudflare, you can choose whether the record should be:

  • Proxied: traffic goes through Cloudflare
  • DNS only: traffic goes directly to your server

For a normal website, proxied records are usually fine. The important part is that the second domain resolves to the same hosting environment as the first one.

Step 2: Add the second domain in your hosting panel

DNS alone is not enough. Your web host must also know that the second domain belongs to the same website.

In your hosting control panel, add the second domain as one of the following, depending on your provider:

  • domain alias
  • parked domain
  • addon domain pointing to the same document root
  • additional hostname for the same virtual host

The key point is this: both domains must serve the same web root, not different folders.

If the first domain already opens your WordPress site correctly, the second domain should be mapped to exactly the same location.

Step 3: Make sure SSL works for both domains

Before touching WordPress itself, make sure HTTPS is valid for both names.

You need a certificate that covers:

  • example.com
  • www.example.com if you use it
  • example.net
  • www.example.net if you use it

If one domain is proxied through Cloudflare, also make sure the origin still has a valid SSL setup. A dual-domain setup is much easier to troubleshoot when both domains already load over HTTPS without certificate warnings.

Step 4: Make WordPress domain-aware

This is the part that actually makes the setup work.

Instead of defining one fixed WP_HOME and WP_SITEURL, you can set them dynamically in wp-config.php based on the current host. That allows WordPress to respond with the same domain the visitor used in the browser.

Here is a safe generic example:

$allowed_hosts = array(
    'example.com',
    'www.example.com',
    'example.net',
    'www.example.net',
);

$request_host = isset($_SERVER['HTTP_HOST']) ? strtolower($_SERVER['HTTP_HOST']) : '';
$request_host = preg_replace('/:\d+$/', '', $request_host);

if (in_array($request_host, $allowed_hosts, true)) {
    define('WP_HOME', 'https://' . $request_host);

    // If WordPress is installed in the web root:
    define('WP_SITEURL', 'https://' . $request_host);

    // If WordPress is installed in a subdirectory such as /blog, use this instead:
    // define('WP_SITEURL', 'https://' . $request_host . '/blog');
}

A few notes about this:

  • WP_HOME controls the public-facing site address
  • WP_SITEURL controls where WordPress itself lives
  • if WordPress is installed in a subfolder, keep that path in WP_SITEURL
  • it is a good idea to allow only known hosts instead of trusting any incoming host header

Once this is in place, WordPress can build links, assets, canonical references, and login paths with the domain the user actually requested.

Step 5: Do not fight the General Settings screen

If you define WP_HOME and WP_SITEURL in wp-config.php, WordPress will no longer treat the values in Settings > General as the source of truth.

That is expected.

For a two-domain setup, this is usually the better approach because the default settings screen is built for one main domain, not two parallel public domains.

Step 6: Test both domains carefully

Now test both domains separately:

  • homepage
  • one blog post
  • admin login
  • media files
  • CSS and JavaScript assets
  • contact form
  • internal links
  • canonical tags in the page source

You want to confirm that:

  • example.com stays on example.com
  • example.net stays on example.net
  • no unwanted redirect happens between them
  • assets are not loaded from the other domain by mistake

If a cache plugin is active, clear the site cache after making the change. If Cloudflare proxying is enabled, purge the Cloudflare cache as well.

Step 7: Think about SEO before leaving both domains public

Technically, serving the same content on two domains is possible. From an SEO perspective, it can create duplicate content signals if both domains are fully indexable.

That does not mean the setup is wrong, but it does mean you should make a conscious choice.

Typical options are:

  • keep one domain as the public canonical version and redirect the other
  • keep both active for operational reasons, but set a consistent canonical preference
  • use both natively only when there is a clear branding or migration reason

If your goal is pure technical access from both domains, the configuration above works well. If search visibility matters, spend a moment on the canonical strategy too.

Final thoughts

Running one self-hosted WordPress installation on two domains is not mainly a WordPress problem. It is a coordination problem between DNS, hosting, SSL, and application configuration.

The short version is:

  1. point both domains to the same server
  2. map both domains to the same website in your hosting panel
  3. ensure SSL is valid for both
  4. make WP_HOME and WP_SITEURL respond to the current host
  5. clear caches and test both domains end to end

If you want to see this setup in the real world, you can test it on my own site using thomas.tropper.eu and thomastropper.com. Both domains point to the same self-hosted WordPress installation and are configured to work natively without redirecting to each other.

Once that is done, both domains can work natively without forcing a redirect, while still using one WordPress codebase and one content database.

Related Images: