How to Host Images on Sub-Domain in WordPress for Better Loading Time ?

Why we need to host all images on Sub-Domain ?

  1. Whenever we upload image to image gallery , It is by default uploaded in the upload folder at following path -
  1. Browser can send 7-8 requests at time to different domains. So if we host all our images on same host then time require to load all images will be more as browser will get images one by one.
  2. If we host images on the sub-domain then images will be ideally at different location , and browser can send simultaneous http request to get images as well as content.

Steps to Host/Serve Images from Sub-Domain :

Firstly make sure that you are going to host all images on your sub-domain to improve site loading time.There are much more complications while doing this. But don’t worry we have written this article to solve your problem.
We are going to consider following two cases -

  1. WordPress is installed on Web Host where you have hosted Single site.
  2. WordPress is installed on Directory
  3. WordPress is installed on Web Host where you have hosted multiple sites.

Steps to Host Images on Sub-Domain :

1. Creating Sub-Domain

Log in to your Web-Hosts CPanel, Scroll down and look for Sub-Domains under Domains and click on it.

Creating Sub Domain
Enter a name for the sub-domain i.e img.example.com, give the path of the uploads folder.

Create a Subdomain by specifying name

Document root path will be different for Different WordPress Installation location

WordPress Installation LocationDocument Root
/public_html/wp-content/uploads/public_html/wp-content/uploads
/public_html/xyz.com/wp-content/uploads/public_html/xyz.com/wp-content/uploads
/public_html/blog/wp-content/uploads/public_html/blog/wp-content/uploads
/public_html/xyz.com/blog/wp-content/uploads/public_html/xyz.com/blog/wp-content/uploads

2. Changing the Media Upload Folder

Now You have to log on to WordPress Blog. Go to Settings -> Media and enter the sub-domain in the Full URL path to files with http in the beginning and no trailing slash (/) in the end. Click on save changes.
Changing the Media Uploading File Folder -2

3. Updating URL from Older Posts

Goto PHP Myadmin We have set up Environment for New images but older posts are still referring the older path so we have to change the image URL’s to the newer one.Launch phpmyadmin menu.
Changing the URL of Older Images

4. Redirecting Older Links to Newer Links

If Some of your images are highly ranked in the google then we don’t want to loose our previous visitors just because of 404 Error so write following code in .htaccess file.

We are redirecting links permanently to newer address.