Have you ever noticed pagespeed of blog hosting their image files in a subdomain or in a CDN?
Do you want to host your media on a separate sub domain?
Then this post is for you.
Having a separate sub domain for you blog will helps you by:
- Boosting Page loading time.
- Lowering the bandwidth of the server.
- Helps you look more professional.
- A Self Hosted-WordPress Blog .
- A Domain.
- Your domain must support multiple A records.
Ensure that your web host supports you to host subdomains.
Disclaimer: Do the process at your own risk. We are not responsible for any damages.
Creating a sub-domain for your WordPress blog’s images:
What are Subdomains?
Subdomains are the domains which are the child of main domain (Example: www.google.com is the main domain and the images.google.com is the subdomain).
Let’s come to the topic…
Be sure to choose a correct subdomain.You can create a sub-domain on your own by these steps:
- Go to your domain Cpanel or your domain login.
- Go to Manage DNS.
- Go to A records.
- Create a new record with the unique IP of your domain. (Your website’s unique IP will found on your Web host cpanel)
- On the “Host name” field, enter your new subdomain’s address like “img” or “media”.
- Enter your domain’s IP in the “Destination IPv4 Address”. Finally click on Add Record. (Or follow the image provided here)
Wait for atleast 1-2 hour for your A record to work.
Creating a Directory for your Images Domain:
- Go to your Host cpanel by entering your URL format like this: “www.yoursite.com/cpanel”
- Log on to your Cpanel.
- Click the “File Manager” option under the files section.
- Go to your WordPress domain root directory.
- Create a directory named “Media” or something on the root of your WordPress directory.
- Click on Save.
- Go to your “wp-content/uploads/year” directory and move all your content of “wp-content/uploads/year” folder to your newly created “Media” directory.
Creating the Subdomain from your web host:
You have successfully created a subdomain on your domain manager but you have to add this subdomain to your host for this domain to work completely. It’s also a easy process.
- Go to your Web Host cpanel by entering your URL format like this: “www.yoursite.com/cpanel”
- Log on to your Cpanel .
- Go to “Subdomains” option.
- On Subdomains, create a subdomain exactly with the name you have previously added in your domain manager. (Ex: if you created a domain “img.site.com” on your first step, then enter the same “img.site.com” on it)
- On the next field, Enter the address of your previously created “Media” folder.
Now you can successfully created a subdomain on your host.
Creating a main page for your images directory: (Optional)
If you want to create a main page, where users can see when they enter into your images subdomain, follow these steps.
- Go to “Media” folder on your host.
- Open a notepad file and enter the below code and save it as “home.html”
- Insert a simple HTML page on your host like this:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0
<title>Revealing The Stuffs</title>
<div style=”text-align: center”><input
style=”width: 320px; padding: 4px; font-size: 1em;
margin-right: 5px” x-webkit-speech=”” autocomplete=”off”
type=”text” name=”s” /><input type=”submit” value=”Search
Blog” style=”font-size: 1em; padding: 4px 8px”
<p><strong><em>You are on
our images directory. You can search our site using the
above search form.</em></strong></p>
<p><strong><em>Our main Blog: <a
(‘href’),’Revealing The Stuffs’);return false;”
<p><i><b>Want to create a page like this? Go
ing The Stuffs</i></b></a></p> </html>
Note: Edit www.revealingthestuffs.com with your URL.
Upload your “home.html” to your images directory. Now your Main page be available.
Updating WordPress settings:
UPDATE: WordPress 3.5 didn’t support the Media changing options. So you can’t do the below process. Don’t be panic. You can fix this issue with the use of a plugin. The name of the plugin is “WP Original Media Path“. With the use of this plugin you can add the custom domain like the Media option in previous WordPress versions.
Follow these steps carefully:
- Go to your WordPress dashboard.
- Go to Settings > Media.
- On the “Store uploads in this folder” field enter “Images”
- And on “Full URL path to files” field enter “img.yoursitesite.com”. Replace “yoursite” with your new images site.
- Click on save.
Final step: (No need for Newly started blogs)
You have completed a quarter of your work. Now you can complete this process by updating your SQL database.
Updating your old post’s image to the new location:
First you have to update the SQL for updating your Old post’s image to the new location.
- Go to phpMyAdmin
UPDATE wp_posts SET post_content = REPLACE(post_content,
Updating your previous posts image links with your new images link:
You have to updated your previous images directory to new. But you have to redirect your previous images link with your new link to work.
- First go to your File manager.
- Find “.htaccess” file.
- Add this following (It’s a good practice to backup your .htaccess file before editing)
RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://img.revealingthestuffs.com/$1
Update my link with yours. Now your images be successfully redirected to your new sub domain.
Stuck on any step? Tell me your problem by commenting.