WordPress binds multiple domain names, how to support access from multiple domain names

Modify the wp-config.php file to enable WordPress to bind multiple domain names and access them

A website is availableof.After the website is bound to multiple domain names, in addition to the main domain name, js cross-domain errors will occur when accessing other domain names. How to solve js cross-domain errors? This requires wordpress to support binding multiple domain names.

How to solve the js cross-domain error that occurs after WordPress binds multiple domain names?

Finally, how to support access from multiple domain names? by modifying, which enables WordPress to support access to multiple domain names. Adding the corresponding code to the file can allow multiple bound domain names to access the website normally and avoid js cross-domain errors. by settingOr cancel domain name binding restrictions, which can be flexibly configured according to needs. At the same time, you also need to pay attention to the addresses of static resources to ensure that access to static files such as images can also adapt to multiple domain names. In this way, the need for WordPress to bind multiple domain names and support access from multiple domain names can be realized.

Webmasters who have used WordPress should know that WordPress will bind the current domain name by default when it is installed, and will bind other domain names later, but the link to the page will still be the domain name when it was installed. So today I will share with you how to bind multiple domain names in WordPress or cancel domain name binding restrictions.

Find the wp-config.php file in the root directory of the website and look for the code in the file require_once(ABSPATH . 'wp-settings.php');  Add the following code above it

(It must be above this code, otherwise CSS styles, images, etc. cannot be read.)

WordPress绑定多个域名,如何支持多个域名访问-1

It is not difficult to bind multiple domain names to WordPress and make them accessible independently. We only need to modify the wp-config.php file, find the "wp-config.php" file in the root directory of the site, and then add any of the following code according to your needs.

How to bind multiple domain names in WordPress in wp-config.php file?

Achieve access to any domain name

Note: Add the following code to the wp-config.php file, so that the domain names bound and resolved can access the blog normally, and will not be connected to other domain names.

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

or

$home = 'http://'.$_SERVER['HTTP_HOST']; $siteurl = 'http://'.$_SERVER['HTTP_HOST']; define('WP_HOME', $home); define('WP_SITEURL', $siteurl);

in PHP $_SERVER['HTTP_HOST']  Used to obtain the source domain name. In this way, it can be based on the origin of the WP_HOME and WP_SITEURL Variable assignment to implement WordPress multi-domain binding.

Achieve https access from any domain name

define('WP_SITEURL', 'https://' . $_SERVER['HTTP_HOST']); define('WP_HOME', 'https://' . $_SERVER['HTTP_HOST']);

or

$home = 'https://'.$_SERVER['HTTP_HOST']; $siteurl = 'https://'.$_SERVER['HTTP_HOST']; define('WP_HOME', $home); define('WP_SITEURL', $siteurl);

How to restrict specific domain names from accessing the wordpress website? Restrict access to specific domain names

You can also specify that only certain domain names can be accessed. Pay attention to $domain = array("www.a.com", "www.b.com", "www.c.com"); Change the domain name in brackets to the domain name you need to bind. In this way, you can set it up so that the domain names you added can be accessed normally. Other domain names that have not been added are inaccessible.

Set the website domain name to the currently visited domain name, which means canceling the binding of the domain name. If you do not need any domain name, you can access it.

 

$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']); }

Just put the specified domain name in the $domain array.

How to modify the static resource address to adapt to multiple bound domain names?

Your website can already be accessed by multiple domain names, but there is still a problem, that is, static resources. When pictures uploaded by WordPress are inserted into articles, the address is fixed. After changing the domain name, the domain name of the picture will not be changed, so there is still a problem. The static file address needs to be modified, which can be solved by using the following code:

define( 'WP_CONTENT_URL', '//' . $_SERVER['HTTP_HOST'] . '/wp-content');

Just add this code below the code above. OK, now your website has perfectly broken through the restrictions of domain name binding.

score

Leave a Reply

Your email address will not be published. Required fields are marked *