How to bind multiple domain names in WordPress

WordPress webmasters should be clear that when the WordPress is installed will bind the current domain name by default, subsequent binding other domain links will be a little difficult. So today we are going to see about how to bind multiple domain names in WordPress.

Open wp-config.php in the root directory of the website and add the following content after define(‘WP_DEBUG’, false);

Define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
Define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);

The reason of above two lines code is to set the domain name of the website as the currently accessed domain name, that is, to cancel the binding of the domain name. If you do not need any domain name to access, just a few domain names, you can do this:

$domain = array("www.a.com", "www.b.com", "www.c.com"); 
If(in_array($_SERVER['HTTP_HOST'], $domain)){
    Define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST']);
    Define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
}

Put the specified domain name in the $domain array.

Note:

  • If website is https, please modify the http:// in the code to https:// ;
  • If the website is installed in a secondary directory, change ‘http://’ . $_SERVER[‘HTTP_HOST’] to ‘http://’ . $_SERVER[‘HTTP_HOST’].’/corresponding to the directory name’

After completing the above work, your website can already achieve multiple domain name access, but there is still a problem, that is, static resources, the image uploaded in WordPress is inserted into the article, the address is fixed, after modifying the domain name, domain name of the image will not be modified, so you need to modify the static file address, which can be solved with the following code:

Define( 'WP_CONTENT_URL', '/wp-content');

Add this code to the code below.

admin

Related Posts
Leave a reply
Captcha Click on image to update the captcha .