To get better ranking in Google, one of the major factor is website page speed. Page Speed is one of the part of Google SEO suggestion. So in a wordpress blog we upload a lot of images to make the content more interactive. By default wordpress stores all your uploaded images, documents and other uploads to the wp-content/uploads folder which is part of the same home domain. So while loading all the images and contents from the same domain, it takes much time and page speed is slow. So to avoid this we can deliver the images from a sub domain to increase the page speed as well as SEO ranking. In this post i’m going to share How a guide from LCN.com on how you can Deliver Images from Sub Domain and how to redirect the older images to the new sub domain URL in WordPress.
Before you start want to see the live example, then right-click on any images in this post, then click copy image url and paste it on the address bar. I have configured my images on my sub domain http://img.techtolead.in.
How To Steps:
Creation of Sub Domain:
First thing you need to do is creating a sub domain under your main domain.
For example the sub domain can be like
Name it according to your wish.
How To Create Sub Domain:
Login to your web-host cpanel and navigate to “Sub Domains”.
Enter a name for the sub-domain i.e images.techtolead.in, give the path of the uploads folder which is usually
and click on “Create”.
Adding a Sub Domain in WordPress:
Once after creating the sub domain, the next step is to add and configure in wordpress. Hence the future uploads will be pointed to the sub domain. One of the sad thing is WordPress 3.5 [or later] versions does not allow to add a domain for the uploads folder. But still you can add a custom domain for the uploads folder using this plugin.
Once after installing the plugin, navigate to “Settings >> Media” in WordPress cpanel.
Now under “Uploading files” you can see “Full URL path to files” , Enter your sub domain url without / at the end.
Also if you want to make your images with short url then un-check the “Organize my uploads into month- and year-based folders” check box.
Click “Save Changes”
From now the uploaded files and images will be load from your sub domain.
How To Change the URL of the Older Posts :
Many of the wordpress users including me, has come to know about the sub domain future after starting and posting many contents. So how can we move the older images to load more th new sub domain without losing or re uploading the images. No worries, we can make it using a single line DB update script.
Navigate to the “phpMyAdmin” from your web host control panel.
Now select your wordpress Database and click on “SQL” tab from the nav-bar
Enter the query given below, then click on “Go”. Make sure to replace techtolead.in with your real domain.
UPDATE wp_posts SET post_content = REPLACE(post_content,’https://www.techtolead.com/wp-content/uploads//’,’http://images.techtolead.in/’)
- wp_posts in the table name by default, if you had custom prefix then change it accordingly.
- https://www.techtolead.com/wp-content/uploads// – is the URL of your current uploads folder. Make sure to replace techtolead.in with your real domain.
- – is the new URL [ Sub Domain ] of uploads folder
Now the table was updated and changes was made to the older posts.
Redirecting Old Images to the new Sub Domain:
We have already updated the older posts and now we are in last step to redirect the older image URL’s in the older posts to the new one. All you have to do is enter the following code in the .htaccess file and save it. If .htaccess file isn’t available then create one. By default the .htaccess file will be available in your root directory.
RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://images.techtolead.in/$1
Make sure to replace techtolead.in with your real domain.
All the steps complete. Please follow the steps carefully and once done the images in the older posts will open/load with the new sub domain URL without any loss. Also the future posts will have the new URL automatically on images.
I hope this tutorial helped you in improving your WordPress site page speed.