How To Host Images of Your WordPress Website in a Subdomain


There are a few advantages of hosting the images in your site to a sub domain. Your browser creates multiple connections to a server when opening a website. So, if the image file are uploaded / hosted in a separate domain / subdomain the downloads will be done in parallel and your website will load fast. So when your blog contains more than one image files then its wise to load them from a subdomain to speed up website.

Note:- Before proceeding with ant thing ensure that you have a backup of the wordpress database.

  1. Login to the Hosting panel of your account and choose Subdomains and create a new subdomain eg.

    creating subdomain for hosting images

  2. Now login to your wordpress dashboard and navigate to Settings > Miscellaneous (“Media” in WordPress 3.0) and enter the new location for the images upload folder.

    creating seperate subdomain

    You could not only store images in the folder, but also your css and javascripts can be hosted in the subdomain, you only need make the desired changes to the themes files after that.

  3. As seen in the image above don’t select the check box “organize my uploads into month and year-based folders”.
  4. Here I have used the default wordpress images folder. (It might create a problem if you have subdirectories in there ie if you have organized the uploads into month and year-based folders before). So, its better if you could start using a new directory like public_html/imgs to upload your images.
  5. Now all the images you upload from now on will be downloaded from the subdomain.
  6. If you’ve got some expertise in wordpress then you can continue with the rest of the steps. Else stopping here would do just fine.
  7. => Advanced Level Proceed with Caveat!
  8. If you want to update the images in your post and media library to the new address, so that the previous images also will be pushed to the subdomain, just run these queries from phpMyAdmin.

    phpMyAdmin in wp

    running mysql query in phpMyAdmin for updating images upload  folder

  9. Now run the following mySQL query.
  10. UPDATE wp_posts SET post_content = REPLACE(post_content,'','')
  11. Make sure you dont forget to make the necessary changes to the urls in the query before running it.
  12. The url of images inside the posts will be updated by now with the new domains address. Now we have the url’s in the media library left. So run the following query too.
  13. UPDATE wp_posts SET guid = REPLACE(guid,'','')
  14. Now we need to update the search engines too with the new address for the images and also we need to avoid duplicate content as google would now see two urls for the same image. So open up your .htaccess file in the wordpress root directory and add the following code to it.
  15. RedirectMatch 301 ^/wp-content/uploads/(.*)$$1
  16. Most probably this should be added before the # BEGIN WordPress line.
  17. That’s it, the images will be hosted in the new subdomain.

Amal Roy is the Founder-Editor of Computing Unleashed. A Technology Enthusiast, Windows Adept and a Proud Geek! | Connect with him on Google+

Recent Articles

  • Here’s how to Upgrade Corsair SSD Firmware Properly
  • Here’s How to Speed Up Google Chrome on your Android Device
  • Activating a Clean Installation of Windows 8.1 with Genuine Windows 8 key
  • Creating a Recovery Drive in Windows 8.1
  • How To Get Paid for iPhone Photography
  • 3 Guaranteed Tools to Make Windows 8.1 Faster
  • Lock Mouse Movement While Locking Windows
  • Check Whether any App is Tracking You [Android]
  • Fixing Issues while Installing Windows 8.1
  • Importing Feeds to AOL reader from Google Reader & Other RSS Readers

    • I have a question. Can i leave my old images as it is and going forward start hosting new images on this newly created subdomain. Do i need to follow any other steps other then steps 1 to 6

    • great ! thanks for sharing ! i have done it and it works like a charm !

    • Do I need to install WP in the subdomain directory?
      I created a subdomain on the same host. I can see the subdomain has its own direcotry and it's empty inside.

      • No you dont need to install wordpress in the subdomain directory. You just need to configure the subdomain with the proper route, thats all.

    • Can be applied in an existing blog or just used to the new blogs?

      Abria a problem of redirection?

      • @Filot
        It can be applied to both existing and new blogs. The redirection can be fixed by using this code in your .htaccess file.

        " RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://images.yourdomain/$1 " (without the quotes)

        Make the necessary changes to the above code before using it.

        Good Luck

    Leave a Reply