How to Serve Images from a Sub-Domain [WordPress]

We all know that Google started ranking website based on Page speed. Though the difference due to page speed could be as low as 1%, but it’s one of the part of Google SEO suggestion. In this post I’m going to share how you can host images in a sub-domain and server images to main blog.

Earlier I shared how to use dropbox as CDN, but using Dropbox was a little manual so I wanted something automatic which may also improve my site speed. After searching the web, I found that serving images from a sub-domain also improves the loading time because of the parallel downloading ability of a browser. In this post I will tell you how to serve images from a sub-domain and also redirect the older ones to the new ones.

Creating A Sub-domain

Log in to your web-hosts CPanel, scroll down and look for sub-domains under domains and click on it.

Enter a name for the sub-domain i.e, give the path of the uploads folder which is usually public_html/wp-content/uploads and click on create.

Setting a Sub-Domain in WordPress

Using a sub-domain is really easy. Go to Settings >> Media and enter the sub-domain in the Full URL path to files with http in the beginning and no trailing slash (/) in the end. Click on save changes. Look the image for more clarification.

You have set up sub domain for WordPress images but the older posts still use the complete URL. They can be changed to the sub-domain using the following SQL query. First open phpMyAdmin.


Click on SQL from the nav-bar and enter the query given below, then click on Go. Make sure to replace with your actual domain.

UPDATE wp_posts SET post_content = REPLACE(post_content,'','')

Redirecting Old Images to the new one

Other pages on the Web and Search engines might have indexed your images so it is better to redirect them to the new images which are hosted on sub-domain. All you have to do is enter the following code in the .htaccess file and save it. If .htaccess file isn’t available then create one.

RedirectMatch 301 ^/wp-content/uploads/(.*)$$1

Make sure to replace with your actual domain.

I hope this tutorial helped you in improving you page speed. Do check your website’s speed using these tools and tell us about your new load time.

Do let us know if you prefer serving images from main domain or you also create a sub-domain to server images & files?


Subscribe on Youtube

Article By


COMMENTs ( 27 )

  1. says

    Hi Admin,
    As you are well aware about wordpress latest version has no built in feature to replace path and Url in “Settings>Media” on the admin panel. So i think you should completely review and update your article. You can tell about “WP Original Media Path” plugin in article as well.
    Thanks for writing great articles.

  2. says

    nice tutorials, but it doesnt work at all for me.
    The images on my main domain are not available, even when I’m done in moving it to my subdomain.
    What am I supposed to do?

  3. Rakesh says

    Harsh, I think this is now a feature that is unavailable in wordpress latest versions. I do not find the media file path option and nothing like the screenshot proves to be working with latest versions. Waiting for your opinion and the real facts about this option ,

  4. says

    Hello..This tricks work for me..but I planned to used a CDN & would like my images back on the original path wp-content/upload…..i had done that by the sql query & deleting everything from Wp-Original-media-path plugin….

    Now Problem is that google has crawl all images from my sub domain and indexed them.. also… as jit dutta told the above redirection in .htaccess file i used them & its working….

    Now can you tell me .htaccess redirection from sub-domain to original path to avoid duplicate content in search engine..

  5. says

    Thanks of the tutorial but i am having an issue….all work fine for me…

    but when i add redirection in .htaccess file it will create redirecting loop because we already changed in the database and again changing in .htaccess file….please advice??

  6. says

    Thank you for the tutorial but I am trying to follow these steps and getting some very strange errors. Not sure what exactly is going on…

  7. Akhil says

    An excellent tutorial. You well explained all steps.

    I just implemented on my site as “”

    Thanks a lot.

  8. chathu says

    After i follow this tutorial, I got 404 error for my sub domain. What could be the reason? Any idea?

  9. Gaurav Pundir says

    Great, But i got a problem, when i am doing this process WordPress 3.5.1 does not support Media Redirection, So please help me for solving this Problem

  10. Jit dutta says

    can i use
    RedirectMatch 301 http://www.techntrix. com/wp-content/uploads/(.*)$$1 in stead of RedirectMatch 301 ^/wp-content/uploads/(.*)$$1 ????? because i have domain in public_html/versedtech. if i follow your one 301 redirect i.e. RedirectMatch 301 ^/wp-content/uploads/(.*)$$1 then it shows broken image at versedtech. but if i use RedirectMatch 301*)$$1.
    can i use my method for this purpose?

  11. says

    I would like to know how to do this on wordpress multi-site where the upload settings options that you mention are not available in the blogs dashboard. Please advise.

  12. Aakash Rohilla says

    Not working man, I have started a new blog, so the Re-direction you have mentioned won’t be useful, so I can manage images on a sub domain from starting, I am trying this but doesn’t works man.

  13. rakesh kumar says

    in my case the sql query to change the location does not change any thing in my database thus leave me in the same position all the time. I am using wordpress 3.1.14. ANy idea what to do now?

  14. Isha Singh says

    well, nice idea to speed up a blog, but have a doubt that do we have to copy “upload” folder or previous images from main domain to a new sub domain?

  15. Karan Labra says

    Quick tutorial there, can you please create something similar related to CDN. I’m thinking to use it in near future but my concepts aren’t that clear about it.

  16. skyafar says

    Cool tip. I heard if we can serve uploaded contents from 4 different subdomains will improve speed alot more as compared single subdomain. How we can set up the same? Will you please explain?

    • Alief says

      no, its bad idea. don’t serve something from many source even that you own subdomain. just use 1, its better.

  17. Deepak Singh says

    An Informative article Yousuf. Serving WordPress Uploads from a Sub Domain seems to be an good Idea. Is there any way to serve Images and Videos from two different Sub Domains?

  18. ash_nallawalla says

    Thanks for a great tip and explained so well. Did your Page Speed score improve by 1%, i.e. does the test recognise this as a CDN?

  19. Mukesh says

    i create but the following error found…..

    404 Not Found
    The server can not find the requested page: (port 80)
    Please forward this error screen to’s WebMaster.

  20. Dinesh says

    Nice idea and explained properly.

    I prefer to deliver images and media from subdomain, which definitely improve the speed and page speed test scores by reducing the requests from same domain name.

    Thanks for the share and I will try this very soon.

  21. Raj says

    using sub domain for hosting images have its own flaws.., wordpress custom functions are not working well with the images which are hosted in subdomain, I have checked them in my site..