[Troubleshooting] Prevent Broken Images In WordPress After Turning Off CDN Service

If you run a WordPress Blog or website and have ever used or are using a CDN service, then it makes a lot of sense for you to read this through. If not, you may still read it for some general tips on redirection of sub-domains. Last year, I got an offer from a CDN service to try it for free. A CDN is a content delivery network which usually speeds up the website performance by hosting a copy of the images and other heavy files on their own network. It helps to improve the page loading time. I opted for it to try it for one of my website which is popular in India.

I used the service for around 2 months, but decided to not use it as the servers of the CDN service provider were not located in or near India from where most readers came, so it made no sense to use a CDN which does not speed up the website. But by then, I had published many articles with images and hotlinked those images from other article too. This caused a peculiar problem after I stopped using the CND service. The articles, where the images were hotlinked, had links of CND url like cdn.exmaple.com/image.jpg instead of my website example.com. So after I cancelled my account, the images stopped serving altogether!

Broken Image

I tried making it work with a rewrite rules in the .htaccess file and adding CNAME entries to the DNS Zone editor, but none of these method seem to work for me. After a series of hit-and-trial, I found out that I can create add-on domains in my hosting cpanel which can be easily redirected. So here is how the problem was resolved:

Step 1: Create a sub-domain

Create Sub-domain

Create a sub-domain with the same name as the CDN service, e.g. cdn.example.com

Create Subdomain

Step 2: Manage Re-Direct

Click on Manage re-direction

manage redirection

Step 3: Redirect sub-domain to domain

Redirect the cdn.example.com to exmple.com and save the rule.

redirect sub-domain to domain

This will start to resolve the cdn.exmaple.com images from the exmple.com domain and the broken images will get fixed.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.