Image uses second-level domain name
Previously, domain names were being transferred, not processed, and not processed after being busy. Today, I want to handle it again. Programmers love to go to HiChina and create a second-level domain name. I found there is no way to create it, in the past, the dns service of the blog was still in Xinnet, so I cut it over and created a second-level domain name of static.111cn.net,
First, we add the following code to the wp-config.php:
// Specify the cookie domain name
Define ('cookie _ DOMAIN ', 'www .111cn.net ');
Then add the following content to function. php in the template directory:
Ob_start ("Static_Switch ");
Function Static_Switch ($ buffer ){
$ Buffer_out = preg_replace ('/http: \/www. phpsong \. com \/wp-([^ "\'] *?) \. (Jpg | png | gif | css | js | woff | woff2 | ttf | svg | eot)/I ', 'http: // static.111cn.net/wp-00001.00002', protocol buffer );
Return $ buffer_out;
}
Because I used the static function of the WP Super Cache plug-in, I had to clear the Cache and go to the page to see if the image address was modified. Then I used the domain name to use Baidu or 36CDN.
Supplement: wordpress static files use second-level domain names
Before doing well found a problem http://static.111cn.net this domain name can access to the home page. Solution: add the following code to the function. Php file of the topic.
# Domain 301
Function url301 (){
If (strtolower ($ _ SERVER ['server _ name']) = 'static .111cn.net ')
{
$ URIRedirect = $ _ SERVER ['request _ URI '];
If (strtolower ($ URIRedirect) = "/index. php "){
$ URIRedirect = "/";
}
Header ('http/1.1 301 Moved Permanently ');
Header ('Location: http://www.111cn.net '. $ URIRedirect );
Exit ();
}
}
Add_action ('ins ins _ loaded', 'url301 ');
Note: Please modify the domain name for the above code
The test is complete. No problem is found, but some problems are solved.