Organize and optimize your uploads directory for a self hosted Wordpress Blog

August 31st, 2008

Wordpress Wordpress (self-hosted) by default stores all your images in the post in wp-content/uploads folder which not only is a bad for SEO but also can cause you trouble in future when your blog gets high traffic. According to Wordpress optimizations if your blog is getting or likely to get high traffic, then all your static files like images, javascripts or CSS files should be moved to another server.

Wordpress options

But as a beginner on shared hosting, you might have not thought this. Though you can any time change the uploads folder to point somewhere else but all your old posts will be having the links to the images in the old folder and of course you won’t like the pain to run the MYSQL queries to edit the absolute link that got stored with your posts.

Better way to organize the wordpress uploads directory to make it more flexible in future is to

Step 1 : Create an upload folder at your root wordpress folder (or may be somewhere else ).

Step 2: Create a subdomain like img.yourdomain.com or let say content.yourdomain.com for general content pointing it to the folder created in step 1.

Step 3: Edit the upload folder from Settings –>Miscellaneous on your Dashboard giving the path to your folder and subdomain created in step 1 and 2 respectively

Wordpress Options

So the image which was earlier at the address  http://www.yourdomain.com/wp-content/uploads/image.png will now simply be at http://img.yourdomain.com/image.png

Advantages:

If in future you think to separate out the static content like images etc to different server then you can simply redirect your subdomain to some other server space without changing the link to your images in the old post and then transferring your old images to that server.

Also you can have multiple such servers running by creating another subdomain if you want to redistribute the static content. Your old posts will point out to old subdomain and the newer posts to the new subdomain.

Changing the image folder also should not be a problem for your old posts as you can point your subdomain to the changed folder now which will preserve the images link to your old posts too.

Share/Save/Bookmark

Related Tech Stuff

Leave Your Comment ↓

  • Frank

    Very Cool! I was trying to do the same but you made the easy easier. Thanks!

  • Nibbie

    Thanks. Was looking for this thing since quite long.

  • Whibber

    Thanks Frank and Nibbie.

  • Mike

    Thanks, but it does not work for me, could you tell me where I am wrong ? I created a folder in my wp root (www.mydomain.com/images) and a subdomain (images.mydomain.com)and now my photos are in the images folder but since they are called like images.mydomain.com/pic.jpg, they just don’t show on the page (obviously)

    Is it maybe because the estructure of my server ? The subdomain is not in the wp root, but in a previous folder, same level as ‘httpdocs’

    Thanks

  • whibb

    Mike, did you point your subdomain (images.mydomain.com) to the images folder correctly ? And one more thing, your images folder should be in the public_html or www folder. Even if it is in some directory, then that directory should be a node of public_html or www folder. Do keep that in mind.

  • Mark Bailey

    Mmm, I’m not sure this works the way you’re saying. You are saying that if you create the new images folder and subdomain, that old images will automatically “simply be at” the new location, without the need to run a mySQL query to change the hard links. It doesn’t work that way for me. All the old images are still in the old directory with the old link.

    “the changed folder now which will preserve the images link to your old posts too.”

    ???