Last update at :2024-06-02,Edit by888u
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.
1. 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 meaning of these two sentences is to set the website domain name to the domain name currently being accessed, which means canceling the binding of the domain name. If you do not need any domain name to be accessible, but only 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']); }
Just put the specified domain name in the $domain array.
Note:
- If it is https, please change http:// in the code to https://;
- If the website is installed in the secondary directory, change 'http://' . $_SERVER['HTTP_HOST'] to 'http://' . $_SERVER['HTTP_HOST'].'/corresponding directory name'
2. After completing the above work, your website can be accessed by multiple domain names, but there is still a problem, that is, static resources. When inserting pictures uploaded in WordPress into articles, the address is fixed. Change the domain name. In the future, the domain name of the image will not be modified, so the static file address needs to be modified. This can be solved by using the following code:
define( 'WP_CONTENT_URL', '/wp-content');
Add this code below the above code.
OK, now your website has perfectly broken through the restrictions of domain name binding.
Recommended site searches: windows virtual host, telecom host rental, Beijing domain name registration, high defense server, US attack defense server, foreign server rental price, Korean virtual host, check your own IP, host server rental, game server rental, < /p>
发表评论