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.
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.
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!
Yes this may improve your loading speed,but your server is still loaded even if try to fetch the images from subdomain !
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.
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
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
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.
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.
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?
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???
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?
Full details of My hosting is here..
http://jpss.in/webhosting.php
” Unlimited plan “
I am not using shared hosting & CDN.
currently my site is http://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 ?
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 ?
EXCELLENT
Do this create a problem while taking wordpress backup ?
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.
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… 🙂
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 ?
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 “
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!
Hi, There is no option page like Miscellaneous under Settings option in WP 3.0 ,How to achieve the above in WP 3.0
thanks for the awesome tutorial.
wow..never tried this things….will try out…i saw orkut also doing the same procedure..!! gr8 info
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.
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?
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.
Thats a very nice and useful info mate,keep up your good work 🙂 🙂
Nice post mate 🙂 Thnx for share
good idea
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?
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.
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.
Nice tutorial.Your blog is really loading faster than previous theme.This theme is really looking good and working well for you except comluv 🙂
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.
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?
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.
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?
Nice tip. thanks a lot Pradeep.
nice post 🙂 buddy