Host your WordPress Images on Subdomain for Better Page Loading

0 Flares 0 Flares ×

Web browsers download a maximum of 4 files in parallel from a single domain, so if a page is having multiple number of images hosted in the same domain the page loading will be slower. So hosting the images in a sub-domain is one of the best way to improve the page loading of your website as the images and other resources could be downloaded in parallel. This will reduce the concurrent connections. So in this article I will explain how easily you can host images in a sub-domain for WordPress site.

WordPress does not support hosting of images in other domain but it supports hosting of images in a sub-domain. So lets see how to host the images for your WordPress posts in a sub-domain and we will also cover how to migrate the old images that are being hosted on the main domain to the sub-domain.

 

Step by Step Process to host WordPress images in a sub-domain

 Create a Subdomain

First of all you need to create a subdomain of your main domain. The process of creating a subdomain depends on the hosting provider, but generally it is a very simple task.

Login to your hosting control panel and create your desired subdomain but I would recommend to create a subdomain with the name “img” (img.yourdomain.com) which points to your current upload directory which is generally “wp-content/uploads”, that is the document root directory of your subdomain should be “wp-content/uploads” (public_html/wp-content/uploads)

 

create sub domain

Change the default image upload location in wordpress

Login to your WordPress site with admin user. Go to Settings-Media for WordPress 3.0 on wards and  Settings-Miscellaneous for wordpress older version. Make the changes as seen below.

“Store uploads in this folder”: The name of the folder where images will be stored, here it will be blank as still the images will be uploaded to the default directory.

“Full URL path to files”: The complete URL to the image location, in our case it would be : “http://img.yourdomain.com” then click on Save Changes.

wordpress default image location change

Even after changing these configuration your files will be uploaded to the default directory wp-content/uploads, so you do not need to worry of taking extra backups and even if you migrate to a new hosting you just need to take the blog backup and create the subdomain.

Note: Till now you have completed the process of hosting your new images in the subdomain, how ever if you want to update the old image location follow the below steps. 

Update old image location

Updating the old image location for the old post is a bit technical task and you need to be more careful while doing it. This step involves modification of your database content. You just need to run the SQL script.

If you have PHPMyAdmin then login to it and execute the below script for updating the old images in your post. Actually here we are going to replace the old image links in the post content with the new links. Please take a DB backup before executing the script to avoid any data losses due to any unwanted mistake.

 

UPDATE wp_posts SET post_content = REPLACE(post_content,'http://www.yourdomain.com/wp-content/uploads/','http://img.yourdomain.com/')

 

Note: Replace all yourdomain.com with your real domain name.

Now the process is completed successfully. Now the performance of your wordpress blog will increase by at least 10-15%. If you have any difficulty in implementing this please do let me know by providing your comments in “Jafaloo comment form not in FB comment form”.

Guru

+Ayodhyanath Guru holds a B.Tech degree in Electrical Engineering and has worked with various prestigious clients in the IT industry and presently working as a Software Engineer. He is a part time blogger and presently authors the Jafaloo.Com blog. Being a tech enthusiast Guru likes to surf the web and blogs about interesting technical topics like How-To guides, freewares, Tutorials, Software, Gadgets, web applications etc. Apart from blogging he likes coding in Java/J2EE and PHP.

You may also like...

8 Responses

  1. Thanks for the post, but pls do i have to edit the .htaccess file, and if so, which of them am i gonna edit

    • Guru says:

      No not required.. As we are updating all the old image link with the new one, we are updating the database. Check the last point: Update Old Image Location.

  2. iAn says:

    Wow! Thanks to this guide. I got all my images in the subdomain. And good thing is, I can still access those images using the old links.

  3. thanks for the tutorial..

  4. Susan Katz says:

    many thanks for this — I have successfully set up a cookieless domain and redirected the images…..this is the only article I was able to find that had good clear direction and screenshots — many thanks, Jafaloo.

  5. I’ve had a problem with this as Google no longer is indexing my images for the site or subdomain. Any thoughts?

  6. abigal says:

    hi, thanks for the tutorial, What should I do with the subdomain, When I visit sub.mysite.com it shows all the images as dir list which I don’t want used to see. shall I redirect the sub domain to main domain or remove access to that place. Some best practice advise or code would be appreciated . thanks

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 0 Flares ×