Page load time is an important metric for Google search ranking. The webpages with better loading time will rank better in the Google SERPS. In some previous articles, I’ve described about how to reduce the page load time of your WordPress blog.
Another issue is still yet to discuss that effectively participate in your page performance. By default the images of your site are hosted in the same domain. This slow downs your page speed. Because, almost all the browsers create maximum two-four connections when downloading a page from the web server. So if your pages contain more than one images then it is wise to host those images in another domain so that the browser can download the images in parallel with your main domain.
How to Host Images on Subdomain in WordPress
WordPress does not support hosting images on different domain. But fortunately, it supports and allows to host images on a subdomain. This article is about how to host your website post images in a subdomain along with the old images which were hosted on the main domain.
Create a Subdomain for your site
In order to get your subdomain you’ve to log-in to your domain control panel.
Point to Subdomains and create your subdomain, provided your domain resides under
Note: The facility depends on your hosting provider. So if you are unable to create a subdomain then contact your hosting provider.
Change default image uploading folder in WordPress
This step involves in setting WordPress to change the default uploading folder for the post images. log-in to your WordPress dashboard. Click on
“Miscellaneous” “Media” under “Settings” from left side of the dashboard.
Fill up the fields as follows: Store uploads in this folder : images Full URL path to files :
Click on “Save Changes”. Now whenever you will upload any image to your post, the images will be uploaded in the subdomain:
Update: From the release of WP 3.5, the option for custom uploading path has been removed from the ‘Media settings’. But you can still choose the location of the ‘upload’ folder by following various methods. The easiest and best way to bring back the option under the WordPress ‘Media setting’ is using this plugin. This plugin brings the old option back. However, you can uninstall it after finishing the path setup as WordPress won’t remove those options until you make them as blank. So, if you are a user of WP 3.5 or higher version, just install the above plugin and get your job done. Once done, uninstall the plugin.
Update the old post images location
You’ve just changed the upload location of your post images. So the images of the new posts will be uploaded into the subdomain. But what about the old post images? Changing the location of all the old images one by one is a stupid job. So, at first download all the folders containing the images under
/public_html/wp-content/uploads/ from your server.
Now, upload all those folders in the folder
/public_html/images/. To update the new location of your images, you have to execute a simple SQL query on your database. You can do this from the phpMyAdmin in your domain control panel.
Click on phpMyAdmin > select your database from the left side > click on the “SQL” tab.
Now put the following query in the box
UPDATE wp_posts SET post_content = REPLACE(post_content,'http://www.yourdomain.com/wp-content/uploads/'
Click on “GO”. This query will replace
"http://images.yourdomain.com/" in all the image location URL. To update the images links in the media library run the following sql command:
UPDATE wp_posts SET guid = REPLACE(guid,'http://www.yourdomain.com/wp-content/uploads/','http://images.yourdomain.com/')
Redirect the old images link to to subdomain
You have completed all the task with your site and database. But Google has crawled and indexed your old images. So redirect the old image urls to the new image URLs to let Google know that those images are same. To do so add the following line in your .htaccess file.
RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://images.yourdomain.com/$1
Reminder: Backup your .htaccess file before any change. That’s all to set your subdomain as post-images upload location.
Now this is time to tweak your website for better performance with great page load time. You can use various tools to optimize your website as well as you can view the page load times for your pages right from your Google Analytics account.
Any question is always well come. Put your reaction in the comment section.