Host Images of WordPress Blog on a Subdomain for Better Speed

Page load time is an important metric for Google search ranking. The webpages with better loading time will rank better in the Google SERPS. In some previous articles, I’ve described about how to reduce the page load time of your WordPress blog [1. Speed Up  Blog Improve Page Load Time 2. Install Contact Page Without Any Plugin3. Reduce Page Load Time ].

Another issue is still yet to discuss that effectively participate in your page performance. By default the images of your site are hosted in the same domain. This slow downs your page speed. Because, almost all the browsers create maximum two-four connections when downloading a page from the web server. So if your pages contain more than one images then it is wise to host those images in another domain so that the browser can download the images in parallel with your main domain.

How to host images on a subdomain in WordPress

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

Create a Subdomain for your site

In order to get your subdomain you’ve to log-in to your domain control panel.

Point to Subdomains and create your subdomain, provided your domain resides under /public_html/.

Note: The facility depends on your hosting provider. So if you are unable to create a subdomain then contact your hosting provider.

Change default image uploading folder in WordPress

This step involves in setting WordPress to change the default uploading folder for the post images. log-in to your WordPress dashboard. Click on “Miscellaneous” “Media” under “Settings” from left side of the dashboard.

Fill up the fields as follows: Store uploads in this folder : images Full URL path to files : http://images.yourdomain.com

Click on “Save Changes”. Now whenever you will upload any image to your post, the images will be uploaded in the subdomain: http://images.yourdomain.com.

Update: From the release of WP 3.5, the option for custom uploading path has been removed from the ‘Media settings’. But you can still choose the location of the ‘upload’ folder by following various methods. The easiest and best way to bring back the option under the WordPress ‘Media setting’ is using this plugin. This plugin brings the old option back. However, you can uninstall it after finishing the path setup as WordPress won’t remove those options until you make them as blank. So, if you are a user of WP 3.5 or higher version, just install the above plugin and get your job done. Once done, uninstall the plugin.

Update the old post images location

You’ve just changed the upload location of your post images. So the images of the new posts will be uploaded into the subdomain. But what about the old post images? Changing the location of all the old images one by one is a stupid job. So, at first download all the folders containing the images under /public_html/wp-content/uploads/ from your server.

Now, upload all those folders in the folder /public_html/images/. To update the new location of your images, you have to execute a simple SQL query on your database. You can do this from the phpMyAdmin in your domain control panel.

Click on phpMyAdmin > select your database from the left side > click on the “SQL” tab.

Now put the following query in the box

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

Click on “GO”. This query will replace "http://www.yourdomain.com/wp-content/uploads/"  with "http://images.yourdomain.com/" in all the image location URL. To update the images links in the media library run the following sql command:

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

Redirect the old images link to to subdomain

You have completed all the task with your site and database. But Google has crawled and indexed your old images. So redirect the old image urls to the new image URLs to let Google know that those images are same. To do so add the following line in your .htaccess file.

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

Reminder: Backup your .htaccess file before any change. That’s all to set your subdomain as post-images upload location.

Now this is time to tweak your website for better performance with great page load time. You can use various tools to optimize your website as well as you can view the page load times for your pages right from your Google Analytics account.

Any question is always well come. Put your reaction in the comment section.

Comments

  1. Sariyanta :

    Hi Tanmay, this is a good article, and I applied it already on my website. By the way, can i also put my image themes in my subdomain? and what should i do in order to make everything correct. I want to do this because my theme is kind of heavy theme

  2. Tanmay :

    @Sariyanta
    Happy to know that you found our article useful. Thanks for your nice words. By the way I could not understand what you’ve wanted to do. Do you want to keep the theme in subdomain or the theme images?

  3. Sariyanta :

    That is fast response, thank you, i appreciate your attention.
    What i intend to do is to move my image theme into sub domain.
    One more problem, when i try to upload an image to my subdomain, it showing something like this
    The uploaded file could not be moved to /home/xxxxxx/public_html/img/2010/06. and my subdomain is img.mydomain..
    can you help me?
    thanks for your time

  4. Sariyanta :

    one more thing, what about css and js file? do you have an explanation about this?

  5. Sariyanta :

    Hi again Tanmay, i want to move all the theme in subdomain, and also i want to create another subdomain to store my script file, is that possible? if its possible then how to do it? i’ve tried googling but nothing makes sense to me, i am a newbie, so this kind of article with a complete tutorial will be very helpful.
    thank you.

  6. Tanmay :

    @Sariyanta,
    No, you can’t upload the theme in a subdomain. But obviously you can move some theme templates in the subdomain and call them properly from your main theme templates. The same can be applied for the css and javascript templates.

  7. Sariyanta :

    Okay, thats sounds good, so now i want to host my css and js in my sub domain, how should i call it? which file should i edit? sorry i’m newbie and asking so much question

  8. Tanmay :

    Put the following
    link rel=”stylesheet” href=”your style-sheet location” type=”text/css” media=”screen” />
    replacing the existing one in the header.php.
    Similarly, apply that for javascripts location in that same template header.php.

    Never mind about that. Feel free to ask any question. We are happy to help you. You can subscribe to our RSS feed or Daily news letters from the top of the site. Keep coming.

  9. Jay :

    Really interesting post. I have only just started using WP3 Cache to try and improve my page speed due to sudden increase in traffic however, if that doesn’t turn out well, I will give your images sub-domain suggestion a try and feedback to you.

  10. lemmekillmister :

    Hi Tanmay,

    I have implemented this subdomain and the CDN on a site that i built but right now, i am having a problem with the https.
    When the site is visited through https, i have all my images and javascripts pointing to http://images.demi.com/web/images/x.gif.

    The site loads but with an alert in IE asking for user confirmation because it has both secure and unsecure data on the web page.

    My question to you would be , is there an easy way to get around this problem and let the browser use https when it is https and http otherwise.. ( a relative url something starting with images.demi.com ,without specifying the entire path starting with http)

    I tried this and it does not work
    <img src="images.demi.com/web/images/x.gif" …
    but this works with http
    <img src="http://images.demi.com/web/images/x.gif&quot; …

    Any help is really appreciated. Thanks in advance
    Lemme

  11. Tanmay :

    @Lemmekillmis: Thanks for putting your idea here. By the way, I don’t know even if WordPress supports both http and https at the same address. But I’ll make a research on it. Thanks again for sharing. Hope I can help you on this matter.

  12. Paul B. Taubman, II :

    Tanmay –

    Thank you for your post! I was actually searching for another topic and discovered this. I think that I will implement this on a less important site to ensure I understand everything. Once I do, I will implement on my main site, http://www.AllAboutGratitude.com .

    Is there anyway to benchmark before and after load times (easily)? I have found that some plug-ins are the real culprits of degradation of page load times so I have deleted them. I should probably delete a couple still!

    Again, thank you. Sorry for the long comments.

    Be Well.
    Paul.

  13. Ram :

    Hi how to do this in wordpress 3

    • Tanmay :

      The procedure for WP 3 is same as mentioned in this post. Follow the instructions and let me know if any problem arises.

  14. gymgangsta :

    This is a great tip! Works like a charm for 3.0.1. However when creating a child directory within the subdomain, the flash uploader is not recognizing the child directory? it creates the images directory within the wordpress files. Any ideas?

    Store uploads in this folder: images/directory-name
    Full URL path to files: http://www.mydomainname.com/

  15. Tanmay :

    @Gymgangsta: did you check the file permission for that directory?

  16. gymgangsta :

    Hi Tanmay,

    I did check permissions, made the directory 777, no luck. I did not check the permissions for the subdomain “images” you think that is the problem? My paths are correct right?

    cheers for the fast response and for your code above, it is really a timesaver…

  17. Tanmay :

    I think some thing wrong that is preventing the image directory recolonization. I also use this method for this blog and working fine. But how can I find problem with out seeing the code? Can you send a screen shot of the media setting? You can upload that from http://www.oxhow.com/update-facebook-status-from-twitter/ . Feel free to ask more question.

  18. gymgangsta :

    i listed my settings above: here it is again.

    Store uploads in this folder: images/directory-name

    Full URL path to files: http://www.mydomainname.com/

  19. Tanmay :

    I can’t understand what the hell is going on. You can try the following

    1. Type the full location of the folder at “Store uploads….files:” like /public_html/images/your-dir
    2. log out from WP and then log-in again. Then try to upload.

    If those does not solve then you can submit you site to our service section.

  20. gymgangsta :

    Thanks Tanmay, I’m quite savvy with wordpress, and this stumps me too. I’ve tried a few things, letting wordpress create the directory (so it has ownership) etc, I’ve tried various path combos, I’ll try your suggestions tomorrow when i am back at the grind again.

    cheers! =)

  21. gymgangsta :

    Hi Tanmay. I tinkered with it some more and am thinking this. My wordpress is installed in a subdirectory (www.mydomain.com/wordpress/

    and no matter what path I set for images to my subdomain (images.mydomain.com) it wont show up. I’m thinking it’s an .htaccess problem and not a permissions problem. I’ve got some crazy stuff in my htaccess. So i’m gonna just upload these images into the content/uplaods folder then move them manually and specify the correct link.

    =)

  22. gymgangsta :

    Hi again Tanmay, on a side note…. I did the same thing for videos. I created a videos.mydomain.com and noticed my 404 error logs (in the redirection wordpress plugin log) are reporting /crossdomain.xml

    further investigation leads me to a confusing doc: http://kb2.adobe.com/cps/142/tn_14213.html

    maybe you could write an article on what would be the perfect code for the crossdomain.xml and exactly where it goes.

    I gather the file crossdomain.xml resides at the root of http://www.mydomain.com so that it can serve up flash video from the subdomain: videos.mydomain.com

    the code would be:

    cheers !

  23. Jim :

    Well written sir.

    Of course the other alternative is to host all images on a free hosting site like image shack, flickr or Picasa, and referencing them from the blog. Two benefits are that it allows me to avoid bandwidth and relies on their server speeds.

    Can you comment on the benefits and concerns of a subdomain vs. a remote host?

  24. Tanmay :

    Jim: Your points are really appreciating. But they all end at one question. How much do you depend on a third party service about the security issue of your assets?

  25. Jim :

    Good point Tanmay. Although if Flickr or Google has security issues, there will be a much larger issue than just my blog! haha.

    Actually, I almost always use others’ pictures available in the Commons to illustrate my posts, so my personal pictures are not in general at risk.

  26. Kunal :

    @gymgangsta:- the problem is in your image upload file path.

    If you are on shared host,you need to use the entire path right from /acc/public_html……..etc

    Hope this helps.

    BTW,thanks Tanmay :)

  27. Tanmay :

    John, just delete the paths that you’ve provided under the Miscellaneous settings.

  28. Mustafa :

    Hi Tanmay, great article.

    One question, if i want to store my data on another domain (not-subdomain), how should i set uploading setting from WP?

    I mean instead of having static.domain.com/img/xyz.jpg
    i want to use, http://www.staticdomain.com/img/xyz.jpg

    I’ve read some articles and realized that another domain option is way much better.

    What do you think?

  29. Tanmay :

    Mustafa: If you are in WordPress then it does not allow to host images/videos in different domains.
    What You have read about the different domain is hosting your assets in different domain boosts your blog performance. And the subdomain works like a different domain in that very purpose.
    You cam also host your images from some Content delivery network (CDN). But there also, the domain name should like a subdomain. e. g cdn.amazon.com.

    Atlast,
    if you want not to use subdomain then host them in another domain and insert the link in your WOrdPress blog. But you will not be able to upload or manage those images/videos from your WordPress blog (main domain).

  30. eGosip :

    Hi, nice sharing…
    I have blog about Celebrity Gossip and I need to host media library in other hosting.
    Please tell me how to configure it.

    Thanks

  31. laptopy :

    I was suggested this web site by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my problem. You’re amazing! Thanks!

  32. Prishtine :

    Thank you so much with regard to giving me an update on this topic on your site. Please know that if a brand-new post becomes available or if any improvements occur about the current post, I would be thinking about reading a lot more and learning how to make good usage of those strategies you talk about. Thanks for your time and consideration of others by making this web site available.

  33. Decio :

    I’m reading about this issue on google, but it seems to me it would be easier to use the Supercache plugin and cache it somewhere else via CDN. Less hassle, wouldn’t it?

  34. Tanmay :

    Decio: Yes, you can setup this via Supercache plugin. Many people do not use Supercache or such plugin. This method should help them a lot.

  35. Ankit Jaiswal :

    Hello Tanmay,
    i have question. i have two domain for say domain1.com and domain2.com if i upload all my images at domain2.com and call images from there for domain1.com then would domain2 will have any benefit for this

  36. mua sam vui :

    remember : to be the best for SEO you can host images in a subdomain –> not other domain e.g images.mmm.com (not images-name.com and your site is eg.com)
    When a visitor come to see your images in images search or someone copy your images – –> it;s been count for your site ….

  37. Tanmay :

    In this case all your images will be indexed in Google with domain2. But I think that will not benefit domain2 so much as Google does not like the domain without any text.

  38. Ankit :

    Hey tanmay i am still unable to upload the images on my blog as it is uploading on my old domain. i have change the required settings exactly as you told. although now my blog is calling all the images from my new domain but unable to upload it on new domain.
    if possible can you please tell me how to change settings from functions.php what i need to change in functions.php so that all my images uploads from my new domain………

  39. Tanmay :

    Sorry Ankit. I forgot to update the article. Go to Settings > Media instead of Miscellaneous. I also updated this post. Now follow and let me know if you are able to upload your images to your subdomain.

  40. Ankur :

    Hi Tanmay i currently have a website hosted on server that are almost private so no problem regarding speed and other issue but there is limitation regarding webspace i have only 1 GB, is there a way to host my files on different host (No CDN service like amazon) i mean like free webhosting out there, is there a way to use them..

  41. Decio :

    @Ankur
    You can host you entire site for free on google app engine. Search for google app engine static and follow this tutorial:
    http://www.labnol.org/internet/host-website-on-google-app-engine/18801/

  42. Li-An :

    What about SEO ? I manage a blog based on images and accept hotlinking as Google count them as valid link to my site. What will happen if I move them to subdomain ?

  43. Andre :

    Hi Tanmay. I’m not sure if this is possible with WP, but if read/write permissions are not an issue, could this method be used to get WP to store images on a completely different server through a different URL?

  44. Tanmay :

    WP means WordPress? If so then this tutorial is completely working for WordPress. This tutorial only allows you to host images to a subdomain of your main domain.

  45. Andre :

    Yes, my apologies, I generally refer to WordPress as WP, makes it easier to write.. Thanks for the prompt response, I guess I’ll have to keep hunting for a plugin to do this then. I’m sure it must be possible somehow, I just haven’t found out how yet…

  46. Tanmay :

    @Andre: If you really want to host your images in different domain Try some CDN like Amazon : http://aws.amazon.com/cloudfront/

  47. Andre :

    Thanks Tanmay, this was something my brother asked me to look into. He was asking me if WordPress was capable of using photos he currently has in some Google-based storage (I think he meant Google Docs, but I’m not sure). So when I found this blog post I thought I’d at least ask and see.

  48. Charles D :

    I’ve been looking for an idea like this. I was going back & forth between hosting images on the domain, and using a image hosting service. I’m giving this a try next, thanks for the tip! :)

  49. Raj @ Blogging Tips & Tricks :

    Thanks for the detailed guide.. i am planning to change my webhost next month and decided to move images to a sub domain.., mu query is whether to host images in the same web server or use a CDN network for hosting images??

  50. Amar :

    Hi Thanks for tips. its really cool.I have configured everything as mention in your post. I am not having issue with old images but while i uploaded new images it went to old wp-content/uploads directory. I would like to mention here that i have configured ” Full URL path to files” as instructed in post. While full url path is set then why images are getting upload in default directory? Please help me.

  51. Amar :

    HI. My problem has been solved. Thanks. I must say your writing is simple and complete and I really appreciate that. Most of tips or tricks available on net are half written or sometimes i do not get idea that what writer asking me to do. Labnol is one of finest technical blog but while you read-how to setup image folder for wordpress, you lost some where because of half written article. Please continue simple and complete writing. Thanks

  52. Stuart Edwards :

    Hi, thanks for this post.

    Been really struggling trying to set this up with my host (123 Reg).

    They are basically saying that what I’m trying to achieve (which is what this post is about) is impossible.

    I’ve purchased a subdomain from them, and when I follow the guidelines set out in this article, I get a SQL error message

    “The this error pos up at the top : #1146 – Table ‘aminearlythereyetco_837484_whatever..’ doesn’t exist”

    They have provided me with a work around, but I’m not sure whether it’s the right thing to do… this is what they have proposed..

    “You can load you images into a folder on your hosting package and make that url (aminearlythereyet.com/folder/photo.jpg or aminearlythereyet.com/folder) live. Then you will have to create a framed fprwarding rule in order to forward your subdomain to that specific url by following the steps from this link: How do I add 302 (Temporary) Web forwarding?
    Also the media.aminearlythereyet.com subdomain will have to be pointed to the webforwarding IP address 94.136.40.82 by following the next steps:
    log into your control panel, select the aminearlythereyet.com domain from the drop-down list and click “Manage”
    click on “Manage DNS” button an then on the “Advanced DNS” tab
    point the “media” record to 94.136.40.82 instead of 94.136.40.103
    Please note that any DNS change needs time to propagate 24-48 hours. This way when you will access media.aminearlythereyet.com you will be forwarded to aminearlythereyet.com/folder/photo.jpg and the url in the web browser will be media.aminearlythereyet.com.”

    Any advice would be really helpful. Thank you very much!
    Stuart

  53. Bobby C. :

    Hello and Thank You for this great post. I followed your directions and it seems some of my images are updated and working and others will not work. I have even tried uploading the images from pc and replacing them with the updated image and they will not appear. I am lost and could certainly use someones advice or help. My pages are a mess now and I dread manually recreating everything. I’m sure there is a painless way to fix my problem. If anyone with more database experience would give me a hand, it will be greatly appreciated. Thanks in advance for any support.

  54. BeautyPirate :

    For some reason it only worked like this for me:

    Did NOT work:
    RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://images.mydomain.com/$1

    DID work:
    RedirectMatch 301 /wp-content/uploads/(.*)$ http://images.mydomain.com/$1

    Part from that, easy to follow tutorual!

  55. Pritesh Taral :

    Sir, I want to know that, If i change my upload path as subdomain for my future posts without moving old images to subdomain .. then will it give any error ??

  56. gaurav :

    great information. I am a novice in wordpress and own a website and i need at least 3 images in a single post, i am using photobucket pro account to host the images and insert them into my post but recently i have started reading about SEO from images and found that it is better to host images on the same domain for better ranks but i am confused where should i have images and what will be better for seo. Will saving images in subdomain is better for seo or just just make mywebsite/Imgaes to store them.Some people say that search engines see subdomain as another domain it will not be good for seo? please suggest me what should i do to get better SEO

  57. Beatrice :

    I have WordPress 3.3.1 and tried the suggestions here but am running into some problems. I made a subdomain within my cPanel called “media” – my wordpress installation is on the root of my domain (not in a subfolder). This is how I set it up in Settings > Media:

    Store uploads in this folder: /media (it's on the root public_html/media)
    Full URL path to files: http://media.mydomain.com

    Without the beginning slash in /media WP just makes a folder called media within the wp installation, which defeats the purpose of parallelising.

    With the beginning slash in /media, I get the following error whenever I try to upload an image:

    Warning: copy(/media/imagename.jpg) [function.copy]: failed to open stream: Permission denied in public_html/domainname.com/wp-admin/includes/file.php on line 348
    1557

    Line 346-349 of file.php says:
    // Copy the temporary file into its destination
    $new_file = $uploads['path'] . "/$filename";
    copy( $tmp_file, $new_file );
    unlink($tmp_file);
    Line 348 specifically is the copy ( $tmp_file, $new_file );

    If I leave “Store uploads in this folder” blank, I get no error, and after “crunching” it shows the correct filepath (http://media.mydomain.com/imagename.jpg) but it’s not actually uploading it there. When I check on the server, it’s not there at all!

    I’m really hoping you can help me – I contacted my hosting company, and the subdomain folder is CHMOD 755 so the permissions are not preventing WP from writing to it directly.

    I don’t know how to fix this so I can use my subdomain to properly parallelise images on my WP site…

  58. julian :

    i tried your tips, it was almost succes, i still had problem with the galery link, before it was posturl/images name.jpg, but after moving to subdomain it is become, post url/sub.domain.com/imagename.jpg

    is there any =one can help me??

  59. Tanmay :

    Just do everything with high concentration. There are two database updates there. The first one to change the source url of your blog images. And the second one is to change the link url of the images. when you run the sql query, make sure that the old url part and the new url part are written properly….suppos you had the old image url as

    http://www.yourdomain.com/folder/xyz.jpg

    now after moving them at your subdomain, it should be

    http://sub.yourdomain.com/folder/xyz.jpg.

    so the sql query for that update will be

    UPDATE wp_posts SET guid = REPLACE(guid,'http://www.yourdomain.com/','http://sub.yourdomain.com/')

    Once again if you want to put the images at another folder name or location instead of the same name as it was before you can cleverly make your query to replace the older url with the new path…

    You can ask any time with your specific query here. Thanks for your comment.

  60. mrPerezMarc :

    I’d like to expand on your Idea. How would you go about loading image from 2 different host name pointing to the same image folder?
    so if you have 10 images, 5 are loaded from images1.mydomain.com and the 5 others are loaded from images2.mydomain.com

  61. Sk :

    Hi i made subdomain and poninted images to uploadin in subdomain

    but instead of uploading in image.domain.in it is uploading in domain.in/http://images.domain.in

    here domain is my domain……..please reply faster

  62. bappaditya :

    Good tricks. thanks for sharing with us
    I just follow your advices and its work .
    My page load time reduce to half
    Thanks once again.

  63. Stow :

    I’ve just managed to move all my post images in a “cookieless subdomain” and serve them in this format (path) when a user accesses the post: img.domain.com/year/month/file.jpg (1)

    Now all my old images have this format but everytime I create a new post and upload an image, the image path shown is this: domain.com/img/year/month/file.jpg (2)

    So what I’m trying to do is to force the site/server to use (1) instead of (2).

    I’ve already tried everything in Media Settings tab, the only thing working is to write in the “Store uploads in this folder” and “Full path to files” fields the subdomain name (“img” that is).

    The path for images in your article are the best example.

    Any suggestions?

    I’m thinking is a Cpanel setting I’m doing wrong.

    Many thanks!

  64. Stow :

    Ok, thanks for your reply. I’m worried though that there’s nothing to propagate since it’s just a subdomain with images and not a CNAME change for A records.

  65. Stow :

    Hi.

    Yes, the subdomain is working fine, I think all the settings are correct there. And yes again, the site address I’m using is the one with the problem.

  66. Stow :

    Tanmay, yes, all the images are serving from subdomain at this point because I haven’t published any other post since.

    As you can see, since I’ve posted my first comment to this moment, there is no new post.

    But I have tried to post new stuff and the images turn the unwanted path.

    Any other ideas that might help, please?

    Thanks!

  67. Stow :

    Tanmay, I think I might’ve made it completinmg your indications here with this: http://wordpress.org/support/topic/uploads-folder-outside-wp-root?replies=13

    the “/home/user/public_html/images” does the trick!
    Although I’ve just found that setting “define” cookie domain in wp-config is making the admin and any user unable to login. So I’m kinda back to where I’ve started but at least the first part, serving the path correctly is happening.

    Thanks so much for your assistance!

  68. Clay :

    Hey guys,

    I have a question! I recently made a sub-domain for the website, images.clayhowardsmith.com I followed the instructions above, but I’m having some issues. I’m using wordpress to manage my site and now when I try to post something new the images appear as broken files. I changed the upload direction to my images sub domain, but it still isn’t working!

    Any ideas would be appreciated,

    Clay

  69. pgrytdal :

    Hello!

    I have done this with a fresh install, and when I try to upload images, I get this error:

    “NAME.png” has failed to upload due to an error
    Unable to create directory /images/2012/06. Is its parent directory writable by the server?

    Whats wrong?

  70. Tanmay :

    @Pgrytdal: You should make the directory /images writable visiting your hosting conntrol panel or using FTP client. If you are not familiar with that, contact with your hosting provider.

  71. Vaibhav Bathla :

    Hello

    Its not working for me. Image gets uploaded but when i copy the link it shows “500 Internal Server Error”. I have wordpress installed in a sub directory named WordPress (public_html/Wordpress) but the sub domain is in the root directory i.e public_html/images.

  72. Hemant :

    I have done all the steps. Images are also being loaded from sub-domain but I have a problem. When I apply the htaccess file redirect, it is also redirecting my other domain images hosted in the same hosting account to the same sub-domain. Further explanation :

    I have 2 websites geekyminds.com and geekyinspirations.com . I want images for geekyminds.com to render from images.geekyminds.com . But when I apply your redirect (RedirectMatch 301 ^/wp-content/uploads/(.*)$ , it is also redirecting my other site’s images. Please give a command that is domain specific. I played around but could not find a specific solution. Do reply urgently.

  73. Keshav Saini :

    Hi Tanmay,

    Thanks for the detailed illustrations. I have a doubt though. I have quite a large number of posts in my blog and many of my images ranks very well in search results.

    So If I don’t run the sql query to update existing image paths, would it be possible that the older images load from same directory and any new blog post will automatically start uploading images to subdomain folder?

    I hope you understood my point.. Basically I want to keep my existing images folder in the wp-content folder itself and move future uploads to subdomain folder.

  74. Keshav Saini :

    @Tanmay I didn’t get you. So asking the same question again….

    Can I skip the sql query part to update old posts images links so that the old images still remain in the same wp-content folder and new images are automatically saved in subdomain folder?

  75. Tanmay :

    Yes!! You can skip that part i.e you do not need to run this query :

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

  76. Barry :

    OK, great tutorial, however, I worked for existing featured images, but I cannot add pictures anymore. I can insert pics in the products/messages but I cannot set pictures as featured images. The picture turns blank. If I resize the image i can see it…when I edit and save it..blank again. weird. Who knows what to do? and I I can’t make it work? how do I reverse these action in the SQL server?

  77. Zanchit :

    How does it work with NextGen which stores its images in a completely separate folder (wp-content/gallery)?
    I have downloaded and re-uploaded the gallery folder and the uploads folder into images.zanchit.co.uk but not sure how I go from here as regards NextGen. Many thanks

    • Tanmay :

      Do every thing described in this article step-by-step. This will configure your WordPress to serve images from subdomain as well as it will upload the new images at the subdomain folder. All the things will work in your new or old posts but for NextGen, you have to configure your gallery(s) to fetch the images from the subdomain folder.

  78. James :

    Nope. Doesn’t work, regardless of how many times I reconfigure it.

  79. Zaneous :

    Hi Tanmay,

    I’m really in need of help as my hosting want to suspend my hosting account, I really need to know how can I change my existing posts(old posts) images to the new path for years and months.

    The hosting recommended me to go for VPS which I do not have the budget for it.
    Does the above steps able to change my existing post images to years and months format?

    Sorry for the inconvenient cause, I hope for your reply soon.

    Hosting email: “In order to resolve this, you will need to clear the folder bellow or redistribute it’s content so that no directory exceeds the 2,500 files limit, we were forced to suspend your account, against our wish – until you will provide a response to our inquiry.”

    Best Regards,
    Zaneous

  80. Tanmay :

    @Zaneous:
    You should understand the fact. The WordPress distributes the image files in subfolders according to months and years. So your existing post images are linked with that images with corresponding paths of the folders and files. Now, if you want to rearrange them in other folders then you can change the image urls through the database query I have put. But the query structure should change according to your need. Suppose, you replaced the the images from the location: 1. yoursite.com/wp-content/uploads/2012/03/imagename.png to 2. yoursite.com/wp-content/postimages/2012/03/imagename.png , you can then use the above SQL query to change all the image source links having the structure 1.
    e.g
    UPDATE wp_posts SET post_content = REPLACE(post_content,’http://yoursite.com/wp-content/uploads’,’http://yoursite.com/wp-content/postimages’) .

    Do the same for the GUID database query I have show into these post.

  81. Zaneous :

    Hi Tanmay,

    I have 8800 files in my ~~/upload directory without years and months folder in it,
    I believe is due to the old WordPress version when I started it.

    By doing the SQL query replace to ‘http://yoursite.com/wp-content/postimages’ will it automatically create the years and months folder for the existing old post images?

    • Tanmay :

      No, this will not do that. And my guess is that you can never divide the existing post images into months-year folder automatically. If you really want to distribute your old images in year and month folders then you will have to do that manually.

      But you can keep your new images organized into month and year folders by selecting the option at your WordPress dashboard > Settings > Media . In Media setting check the option called “Organize my uploads into month- and year-based folders”

  82. Zaneous :

    Hi Tanmay,

    I like to ask if I can transfer to another hosting, is there anyway I can do it in a faster way then manually uploading the pictures of the existing posts?

    Really thanks and grateful for your prompt reply.

    Your sincerely,
    Zaneous

    • Tanmay :

      You can transfer the site any time to a new host. Keep the existing post as they are. Now, set the upload option for the new posts as I mentioned earlier.

      Later, you can rearrange the old post images manually one by one. No shortcut way. Feel free to ask any thing else.

      But one thing I can’t understand that what is the problem with the old images. It does not matter whether they are in a single folder or organized in different folders.

  83. Ramanath Jha :

    Is it safe because I do not want to loose my visitor.

  84. Ramanath Jha :

    Hi Tanmay,

    I saw your article and I want to improve my website http://hotindiandealz.com, and I created subdomain but I did not find ‘media setting’ change image folder setting. I am using WordPress version 3.6.1.

    Can you help me?

    Thanks
    Ramanath

    • Tanmay :

      Actually, the custom upload location under media setting is removed from WordPress 3.5 and the later. Use this plugin to bring it back. http://wordpress.org/plugins/wp-original-media-path/ . Don’t worry, once you set the custom upload path, you can uninstall the plugin.

  85. baby hazel :

    It’s not the best solution!

  86. David :

    Does this works in a WP multisite network?

    • Tanmay Ahmed :

      This should work on WP multisite as well.

  87. Somesh Likhyani :

    Which database we have to select ?

  88. laura :

    I wish I understood how much the time savings would be in some sort of way to understand how worthwhile it is for someone like me to “dive in” and try. I will think about this. Also, since you made me think… do you think this would be a good plug-in to help to do the same thing for major categories?? https://wordpress.org/plugins/wp-subdomains-revisited/ Thank you. (Also, I feel guilty asking someone questions without paying them for their consulting time. Wish I was wealthy at the moment… I’d find someone helpful and knowledgeable and just pay them consulting. Sorry for using your time for free if you answer this!)

  89. Aamir :

    Hello Tanmay,

    Thank you so much, I have moved my Upload folder to a sub-domain now with this tutorial.

  90. Abinash Mohanty :

    Hi Tanmay,
    Very nice article. Actually, I did this few months before after seeing an article on WP Beginner. I have made some security changes via .htaccess file and switched over to TwentyFourteen. My subdomain is “Media” and I can upload images into this directory whenever I try to upload any media. The problem is that on live site it doesn’t show "media.abinashmohanty.com" rather than "http://www.abinashmohanty.com/media/2014/01/download_gesture_icons-672x372.jpg" for an example via this post http://goo.gl/j1YUBV, you can see them by right clicking on the first image and inspect.

    Note* This is only happening with my latest 4-5 articles as older articles show www.media.mydomain.com
    .
    What do you think! what went wrong or overwritten.

    • Tanmay Ahmed :

      After reading your comment what I can guess that the problem is in your htaccess file. Check by deleting the htaccess rules you have added later. If it works, find the problem with the rules you added in htaccess. If not, there must be some problem in your WordPress configuration.

      For the second case, it is tough to guess about the exact problem. In such situation you can submit your blog for review. Don’t worry it is free for the OXHOW readers.

      You can use our contact page with appropriate subject line to submit your blog for review.

  91. Abinash Mohanty :

    Thanks Tanmay

  92. Sam :

    Thanks for the heads up. I knew the option was there before but didnt know it had been removed so the plugin is a great help.

    Many thanks, Sam!

  93. Walter Pinem :

    Hello Tanmay.
    There are so many problems Ive been faced due to follow these tips. How can I undo the settings and roll back my images to my main domain? Please follow up my questions via email, I need your help.

  94. Daniel :

    Hi there, I am wondering if this will work with all other files such as ZIP files? As I have a download site where users can download ZIP files. Does the zip files make page loading any slower or is it just the images when loading pages? NOTE: When I download products from site, its no worries, they all download fast. It is just the page loading, getting very slow. I have 35,000 files within my media library. Any help would be great. Thanks.

    • Tanmay Ahmed :

      @Daniel: The images and the zipped files play differently in the web pages. So there is nothing to worry with the zipped file as they won’t reduce the page load time. Ofcource you can improve the download and response time buy serving them from a subdomain which is actually hosted on a CDN system.

  95. Rahul :

    Hi,

    Nice article and nice solution but what issue I am facing is that as I moved all my images to sub-domain they are not showing up in Media Library, all new images which I am uploading is going to sub-domain and showing up in Media Library but old ones are still missing from Media Library.

    • Tanmay Ahmed :

      Hi Rahul,
      You can only see the media attachments under Media Library if you use the WP uploader to upload images. So, if you placed images directly into the source of your content, they won’t be shown into the media library. But it does not matter for a site.

  96. Glickly :

    Great tip. Will give it a go. The SQL code is a great speedifier instead of manually moving all the files and their URLs etc.

  97. Umer :

    Hey Tanmay Ahmed,

    I have a question! I recently made a sub-domain for the website, images.mysite.com I followed the instructions above, but I’m having some issues. I’m using WordPress to manage my site and now when I try to post something new the images appear as broken files. I changed the upload direction to my images sub domain, but it still isn’t working!

    Any ideas would be appreciated,

    • Tanmay Ahmed :

      Can you give the real url of your website and the folder your images are hosted?

      • umer :

        i am waiting for answer sir

        • Tanmay Ahmed :

          Umar,
          It seems that the subdomain you’re using is not working. It is not working and it returns 403 forbidden. Configure the subdomain properly from your hosting control panel. If you can not yourself, ask your hosting provider to make your subdomain woking properly. Don’t hesitate to ask anything anytime. Have a nice day. :)

          • umer :

            Thanks for your reply sir..

  98. Xongu :

    Hi Tanmay Ahmed,
    Thanks for a good topic. I used WP Original Media Path plugin on WP 4.0 on a site app2u.ca to set up external domain for media upload (img.xongu.com). When I upload files in WP, image links are created to the correct location on external website (img.xongu.com/imagename), but the images themselves are not uploaded there. What do I do wrong? Can you help?

    • Tanmay Ahmed :

      Xongu,
      You can not upload images from WP to an external domain. For example, you can not upload images to xyz.com from abc.com. Rather, you can use the subdomain of the same. You can always upload images from xyz.com to yoursub.xyz.com. Hope this could make the thing clear.

  99. Daniel :

    Hi there, a great article that has helped me a lot. I have a question about the sub-domain. it all seemed to work for me, but when I right click and “copy image location” it shows me the following example of my image URL:

    mydomain.com/images/2014/08/image.jpg

    As my sub-domain is the following example:

    images.mydomain.com/image.jpg

    If i type in either one within the address bar, they both come up. Also when I do a page speed test it shows all my post images are coming from the first domain path:

    mydomain.com/images/2014/08/image.jpg

    So it does not make my page load any faster as it seems like my images are still hosted within my site.

    So my question is, am i doing something wrong or is this how it is? Thanks

    • Tanmay Ahmed :

      You should change the source path of your old post images using the SQL Query…

  100. Sawan :

    Nice tricks, but does it work for good results?

  101. Vivienne :

    Hi – I tried this as a partial solution to a low bandwidth problem where my users will mostly access my website. I have a high graphic content and want to keep it that way if possible. But my website speed tests in Pingdom and gmetrix were at 90% and have since dropped significantly by 6% since taking this step. I have checked the report and it most appears associated with me now needing to leverage caching for the new images location. I’m not quite sure how I do this in WP super Cache or how to do this generally?

    The other issue now appears that it results in giving me http redirects on my home page – and also drops the rating for this.

    Even though I had a 90% load speed before – in my current location actual page load is seriously degraded – so its all very well to have a high efficiency rating in first world countries. But I need both – I need the metric rating for SEO and I need a faster page load for bandwidth mitigation for at least another 12 months out here.

    Any thoughts or knowledge of setting up an alternate text heavy alternative landing page that can continue loading the main home page in the background? We would do this in a corporate environment. Its kind of the opposite concept to a splash page that forces you to watch a flash promo. The only issue with adapting a sales splash or landing page for the purpose would be that if it is only a squeeze or interstitial – it probably won’t load the main page until a secondary link is clicked. I want something that will parallel load. Perhaps there is a plugin of some sort for this. Do you know?

Leave a Reply

Your email address will not be published. Required fields are marked *

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=""> <strike> <strong>