BigCommerce Facebook Store
Do You Want To Get Paid For Writing Reviews & Posts? [SIGN UP] On These Websites & Make Money Online!

Host Images Of WordPress Blog In Subdomain

CONNECT WITH HBB ON SOCIAL MEDIA

Hosting images of your site in another subdomain is one of the best ways to improve the loading speed of your website. Last week, I spend some hours (or minutes) doing this.

If your pages contain more than one image then you should host those images in another domain. By this, the browser will be able to download those images in parallel with your main domain. It will reduce the concurrent connection.

WordPress does not support hosting images in different domain. But fortunately, it supports and allows you to host images in a subdomain. This article is about how to host your website post images in a subdomain along with the old images that were hosted in the main domain.

Create A Subdomain For Keeping The Images

To create a subdomain you need to use your domain control panel. The procedure for creating a subdomain depends on respective hosting provider; normally it is not a tedious task.

You can create your desired subdomain. But image or images or img recommended! πŸ™‚ Create a folder with name “Images”.

Change The Default Image Uploads Folder In WordPress

Log-in to your WordPress dashboard. Now go to Settings | Miscellaneous. For WordPress 3.0.1, Go to Settings | Media.

Subdomain-images

It should be like this,

Store uploads in this folder : Images

Full URL path to files : http://img.yourdomain.com

Click on Save Changes. From now onwards, whenever you upload images, it will be stored in the subdomain img.yourdomain.com

Update The Old Images Location

Now you have updated the upload location of your post images, but what about the old post images? You can’t change the location of all the old images one by one. That’s a tedious task.

First download all the images in the folder /uploads/ and upload them into the folder Images.

Now we have to perform a simple SQL query on your database. You need to use your phpMyAdmin for executing this.

Go to phpMyAdmin and the click on the SQL tab.

phpMyAdmin

Now put the following query in the box

UPDATE wp_posts SET guid = REPLACE(guid,’http://www.yourdomain.com/wp-content/uploads/’,’http://images.yourdomain.com/’)

Click on GO. This query is capable of replacing β€œhttp://www.yourdomain.com/wp-content/uploads/” with β€œhttp://img.yourdomain.com/” in all the images location URLs.

Hurray! Now you have completed the process almost 95%. Considering the images Google crawled and indexed, we have to redirect the old image URLs to new image URLs.

In order to do that, add the following line in your .htaccess file (What is .htaccess?)

P.S. Backup your .htaccess file before implementing.

RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://images.yourdomain.com/$1

Now you are done, perfect!

You can subscribe to our feeds to get quick updates about such tutorials!

Getting any error sort of thing? Do you know any other tip? You are welcome to share!


By

CEO and Founder of Slashsquare, Indian Blog Network and Web Consulting Media. HBB is a part of Slashsquare Network. I'm a Tech Blogger, Striving Entrepreneur, Atheist, and Proud Indian. Catch me on Facebook and Twitter.

  • My Website

Want to discuss your queries and interact with experts? You can connect with HellBound Bloggers (HBB) Facebook group for free!

Join HellBound Bloggers (HBB) and get Instant Updates. We'll also notify you with Great Deals, Discounts and other Interesting Tips. We won't SPAM or SHARE your Email Address with anyone.

Earn up to $7500 for one sale!

Thank you for reading! We welcome and appreciate your comments, but at the same time, make sure you are adding something valuable to this article. If you have any serious queries, suggestions or anything related to this article, feel free to share them, we really appreciate that.

But, if your blog comments are a random "Thank you", "Useful Post", or anything that doesn't actually upscale the article, then we'll be removing them and it won't be appeared below. Thanks for understanding and thanks for connecting with us. If you want to give us any feedback or report any errors, you can kindly contact us and we'll revert back soon.

  • Comments
  • Facebook Comments
  • Comments

    Leave a Reply

    Your email address will not be published.

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

    76 Comments

    • George

      Yes this may improve your loading speed,but your server is still loaded even if try to fetch the images from subdomain !

    • Gaurav Bidasaria

      I decided to go back to the way it was and deleted the sub domain and changed the media settings to the way it was and now none of my images is loading. I can see them in the media section and on cpanel but when I load the site, no images is being loaded.

      Its all messed up. And my create new post is also messed up. I see that your entire post is a poor copy paste job from other sites who have written the article way before you did.

      You did not considered the other factors like wordpress updates and other plugin issues. No thought was given whatsoever. Its a word by word copy paste job.

      This is sad. Wasted several hours to find out and now will waste more hours to fix it.

    • Gaurav Bidasaria

      Its not working on wordpress version 3.5.1 Here some screenshots for various steps and settings. For phpmyadmin I tried two different codes both resulting in same results. Screenshots for both are here.

      I just uploaded the screenshots in my new sub-domain but it is not visible at sub.domain.com

      takeaclick.com
      img.takeaclick.com

      http://img.takeaclick.com/cpanel-sub-domain.JPG
      http://img.takeaclick.com/php-my-admin.JPG
      http://img.takeaclick.com/php-my-admin-2.JPG
      http://img.takeaclick.com/settings-media.JPG
      http://img.takeaclick.com/upload-sub-domain.JPG

    • HanΓ¨ Dunn

      Just a heads up I had to make my settings as follow to get it to work.
      Store uploads in this folder: img/uploads
      Full URL path to files: http://img.domain.com/uploads

    • Fren

      Great tutorial and explanation.
      I just noticed why is it that your site is still hosting images on the main domain? Just asking, I hope you don't mind.

    • Kamal

      Hello Pradeep,

      Hope all is well,

      I would like to know, if i use Next Gen Galleries, how could i change them to sub-domain ?

      Kamal.

    • Klymene

      Interesting!

      How would it work if I point my subdomain to the WordPress default uploads folder?

      What values would I need to provide in
      Store uploads in this folder :
      Full URL path to files :

      By the way, what's the difference between the 2 fields?

      • S.Pradeep Kumar

        In "Store uploads in this folder :" mention the folder name

        and

        In "Full URL path to files :" mention the subdomain URL.

        • Klymene

          So, for instance:
          Store uploads in this folder : /wp-content/uploads
          In "Full URL path to files : http://sub.domain.com

          That didn't work! It messed up my theme, in fact

          • S.Pradeep Kumar

            I think you didn't check the screenshot mate, here it is :

            http://hellboundbloggers.com/wp-content/uploads/2010/06/Subdomain-images.jpg

            I said the "folder name", suppose say "Images" or "pics" like that..

            • Klymene

              Even if the subdomain is pointing to /wp-content/uploads ?

              • Klymene

                Instead of a new folder like Images or something, my subdomain points to /wp-content/uploads because I don't want to physically move the existing files (and also because I want the installation to be self contained).

                Just changed folder to uploads
                and path to http://sub.domain.com

                This has not messed up my theme….that's encouraging…

                I will try to run the SQL query this evening.

              • Klymene

                Isn't the SQL the other way round?

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

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

              • Klymene

                Yup that worked. I had to make the above change to the SQL, and also had to replace the quotes with true single quotes.

                Thanks, Pradeep.

                P.S. As stated above, I set
                Store uploads in this folder : uploads
                Full URL path to files : http://sub.domain.com
                (http://sub.domain.com points to http://www.domain.com/wp-content/uploads)

              • S.Pradeep Kumar

                Thanks Klymene for picking HBB for this tutorial. πŸ™‚

    • Raj @ Blogging Tips & Tricks

      Good tutorial, but my query is whether to use same webhost or use some CDN for hosting the images..

      P.S why haven't u implemented this in your blog???

    • Alyen

      Hi I have already set all the tutorial but when I try to upload a new image will not upload the picture goes blank, that puevo be?

    • Mayur

      Full details of My hosting is here..

      http://jpss.in/webhosting.php
      ” Unlimited plan “

    • Mayur

      I am not using shared hosting & CDN.

    • Mayur

      currently my site is www.amigowork.com

      now i want to store images on my sub domains like..
      img1.amigowork.com
      img2.amigowork.com
      img3.amigowork.com

      Is it possible ?

    • mayur

      Can i use more then one subdomain to store my images ?

      if yes.. then explain me how.. ?

      Which SQL queries i should use for it ?

    • aswin

      EXCELLENT
      Do this create a problem while taking wordpress backup ?

    • Sam@ Managed Hosting

      I’ve been looking to start a new site, but am having a difficulty getting my foot on the ground. Browsing other blogs, I’ve found that a site like Flickr has been known to delete images that’ve you stored on it- if you use it on your own site. Where do you think the best place to host images are? I don’t want to have them on my hard drive and take up the space, so typically I’d prefer an online site/server.

    • Jasmine

      This is a cool trick to host images in subdomain. So, is there a way to host images on another domain? … I know, put in the image URLs MANUALLY…

      Hehe… πŸ™‚

    • thanh

      thanks ! but when i buy a new host and point it to images.domain! i got an error: you can upload your images – maybe y… something like that ! can any body help ?

    • Design Blog

      Thanks for information. one silly doubt, i usually create a subdomain for theme demo and script.

      should i create and subdomain with wordpress install,
      or
      simply create a folder in the “/publichtml/img” -folder in using Filezilla in FTP ?? and change the media link in WP Dashboard.

      ” i dont want to take sudden risk in my blog “

    • cjschris

      Can you please help.
      I get

      #1146 – Table ‘cj******_cj*****.wp_posts’ doesn’t exist

      P.s i put the *’s in just in case.
      Please Help!

      • S.Pradeep Kumar

        I would love to have a screenshot Chris!! πŸ™‚

        • S.Pradeep Kumar

          Got the screenshot mate. Thanks!

          And I think you renamed your wp-posts into something else for security purpose.

          Did you follow all the procedures!?

          When I visited this image URL I was redirected to this image URL (http://storage.cjs.au.com/images/gadgetbag/media/2010/08/Justin+Bieber+90282309-300×190.jpg)

          Did you create separate subdomain or domain for images!? πŸ™‚

          • cjschris

            this is the subdomain where im keeping the images now.
            That’s a new post though so it’s using the new domain, older posts still use the old domain and if they dont look like it, they might have been redirected with the htaccess.

            Oh and i thought you had to change wp_posts to your table name because this happens when I use:
            UPDATE wp_posts SET post_content = REPLACE(post_content,’http://storage.cjs.au.com/images/gadgetbag/media/’,’http://www.gadgetbag.au.com/wp-content/uploads/’)

            Screenshot: http://storage.cjs.au.com/images/gadgetbag/media/2010/08/help2.jpg

            Sorry for the confusions and thanks for your help!

          • cjschris

            have i replied yet?

            • S.Pradeep Kumar

              I think you should check this comment mate,

              http://hellboundbloggers.com/2010/06/13/host-images-of-wordpress-blog-in-subdomain/

              He has replied,

              “Your sql query has the paths reversed. When I first tried it I got β€œ0 rows affected”. When I changed the query to put the path being changed first, then it worked.”

    • Gokul

      Hi, There is no option page like Miscellaneous under Settings option in WP 3.0 ,How to achieve the above in WP 3.0

    • Vector Graphics

      thanks for the awesome tutorial.

    • sureshpeters

      wow..never tried this things….will try out…i saw orkut also doing the same procedure..!! gr8 info

    • Suneel

      Not working for me Pradeep. Checked it and tried it a couple of times. But I am missing something miniscule.

      I will try this later on again.

    • Wendy

      I am a new blogger and followed the directions above. I didn’t need to move any old images since I am working on my first post.

      This may sound dumb, but where do I find the folder on FTP. There was the original Images folder. Shouldn’t there be a second one somewhere?

    • gravman

      A very helpful tutorial. However, I did find some mistakes…

      1) To change the upload path, in WordPress 3 at least, you have to go to Settings > Media. There is no Miscellaneous.

      2) Your sql query has the paths reversed. When I first tried it I got “0 rows affected”. When I changed the query to put the path being changed first, then it worked.

    • Tech Sputter

      Thats a very nice and useful info mate,keep up your good work πŸ™‚ πŸ™‚

    • sidduz

      Nice post mate πŸ™‚ Thnx for share

    • TechChunks

      Nice tutorial. But could you explain how exactly will it speed up your blog’s loading speed? After all, we are storing the images in the same domain name, right?

    • Domain name registration

      This is a very nice and useful post for all blogs who like images in post, I have being thinking that I will not be using image in all my post again, but with is powerful tutorial, I think it is a good method to speed up your blog, if you are the type that like image in post as I do.

    • P.K.ARUN

      Hello pradeep please help me, after implementing this on my site (ashout.com) all my images are moved to sub domain (img.ashout.com) and I also changed the images uploading path in wp dashboard (Miscellaneous Settings). Now when I try to upload images in new post it is uploading properly to correct path but it is not displaying in posts. When I check that images URL it is not showing images just giving 404 error means it is not uploading any images to the new path.
      Please help me pradeep.

      • S.Pradeep Kumar

        I checked your blog. Guess it is fine now.

        It’s working. Any issues from your side mate?

        • P.K.ARUN

          Ya I changed all images address to new sub domain but the problem is, when I try to upload new images in post it is not uploading! Have u installed WP on sub-domian?

          • S.Pradeep Kumar

            Not uploading in the sense bro? You get any error?

            Plz make sure the values in Miscellaneous are as follows :

            Store uploads in this folder : (The name of the folder you have created)

            Full URL path to files : (The subdomain you have created for storing the images)

            And I didn’t install WP on Subdomain!

    • Blogger Templates

      Nice tutorial.Your blog is really loading faster than previous theme.This theme is really looking good and working well for you except comluv πŸ™‚

    • Chandan

      Hey brother you have changed your theme, the new theme also looking very nice. Yes that is one nice tips for increase our blog loading speed.

    • Ajith Edassery@Make money online

      That’s a real handy tip man. I never even thought about it yet…

      PS: I heard that you suffered an AdSense ban lately.. Is it true?

      • S.Pradeep Kumar

        It’s quite simple and worthy bro!

        And yes buddy, my adsense account was banned by Google Inc. πŸ™

        And I can’t able to get the correct reason from them.. still waiting.. πŸ˜€

        Improper ad placements? or SPAM clicks? πŸ™

    • P.K.ARUN

      I seen many of the bloggers uploading there images to subdomain for speed purpose, I’m also thinking to do so after seeing your post. Thanks for this post.

    • Suneel

      Amazing Pradeep. This is surely going to be worked out by me. I had been plying around to reduce the loading time of my blog and I suppose this would help me.

      I realised that your blog’s loading time has come down drastically after you have changed the blog’s look and feel.

      Like your plain theme now. Looks like a news site. What’s the theme?

    • Ram kumar

      nice post πŸ™‚ buddy

  • Facebook Comments
More in Guides, WordPress
WP-Error-close
WordPress Error – Headers Already Sent Warning Problem

Close