Home > CMS Tutorial > WordPress > WordPress binds multiple domain names

WordPress binds multiple domain names

爱喝马黛茶的安东尼
Release: 2019-07-16 15:56:49
Original
2923 people have browsed it

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.

WordPress binds multiple domain names

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']);
Copy after login

The meaning of these two sentences is to set the website domain name to the currently accessed domain name, which means canceling the binding of the domain name. If you don’t need any domain name to access it, 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']);
}
Copy after login

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

Related recommendations: "WordPress Tutorial"

Note:

If it is https, please modify the http in the code: //It is 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, in wordpress The uploaded image is inserted into the article, and the address is fixed. After changing the domain name, the domain name of the image will not be changed, so the static file address needs to be modified. This can be solved by using the following code:

define( 'WP_CONTENT_URL', '/wp-content');
Copy after login

Add this code Just below the above code.

OK, now your website has perfectly broken through the restrictions of domain name binding.

The above is the detailed content of WordPress binds multiple domain names. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template