Wordpress files are configured with second-level domain names (graphic and js/css).

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.