Method 1. Configure a cookie-free domain separately
In this technique, you will create a completely separate domain name for your website. This separate domain is going to host all the static contents without any cookie command to the browsers. So, first of all, you have to register a domain name.
If you already have then skip to the next step but if you don’t have yet buy a new one. You can also create a sub-domain in case don’t want to buy a new one. If you prefer to use sub-domain, use a static prefix so people can understand by looking at the name. For example: “www.static.rankwp.in“
*Remember: If you use your root domain without www version, like rankwordpress.in then using the subdomain as the cookieless domain will not work.
Again, if you are using Adsense advertisements then cookieless domain warning will always occur because your sub-domain is a part of your root domain and Adsense set cookies for every sub-domain under one verified domain name.
1. Create a subdomain
Go to your cpanel and create a subdomain like static.yourdomain.com. From this subdomain you will serve or host all the static files.
Go to subdomains > make sure you are on the page ” create subdomain” > place “static” on the subdomain box > let domain box stay in default name > click on create.
2. Point subdomain to wp-content
Now point the newly created subdomain to the “/wp-content” directory of WordPress installation folder.
To do it again go to your subdomains and edit the settings by clicking on the edit icon next to your new static domain.
It will take you to the document root settings where you need to update the root address from “public_html/static” to “public_html/wp-content”.
Update document root
3. Update your wp-config file
Go to the file manager using cpanel or ftp client and edit the wp-config file. Make sure the following code is available or added inside the file.
- Remember to correct your domain names accordingly.
4. Direct url to new subdomain
Before taking this step make sure you backup your database in awar to any kind of misconfiguration. Better to practice with demo site before applying in live the version. I do not take any responsibility for further loss of data or website down.
Now you need to run sql query on database table. Go to phpmyadmin > select your wp database > go to SQL tab and paste the following code in the command box.
UPDATE wp_posts SET post_content = REPLACE(post_content,’www.yourwebsite.com/wp-content/’,’static.yourwebsite.com/’)
This will make sure all the post urls are directed to the new subdomain.
- Again make sure that you have corrected the domain details inside the code.
Once you setup everything your cookie domain and static domain are ready for action. And the static domain will start delivering static resources without sending unnecessary cookies traffic.
After creating the cookieless domain, Use your .htaccess file to configure your web server to serve static contents without cookies. Here you have to put that .htacess file into the root folder of your domain. Here’s how to find and edit the .htaccess file Once you find the .htaccess file paste the following code there.
# Use Mod_deflate to compress static files SetOutputFilter DEFLATE # Speed up caching FileETag MTime Size # Expires ExpiresActive On ExpiresDefault "access plus 366 days" # Future Expires Headers Header set Expires "Sat, 27 Dec 2018 23:59:59 GMT"