• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • AI Agents
    • OpenClaw
    • Claude Code
    • n8n
    • Hermes Agent
    • Open WebUI
    • Docker
  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
    • Email Hosting
    • HeroicGuard
    • GPU Hosting
    • Website Builder
  • VPS
    • Managed VPS
    • Unmanaged VPS
    • Flex VPS
  • Reseller
  • Gaming
  • Domains
  • Account
  • Blog Home
  • Categories
  • Authors

How To Rewrite Your WordPress URLs To Point To A CDN

Bhagwad Park

Published on: May 1, 2019

Categories: WordPress 0

Subscribing to a CDN is just half the battle. The next challenge is finding a way to rewrite the URLs of all your static assets to the new CDN URL. In this article, I’ll share the best plugin I’ve found for the job, and why other solutions don’t work.

Note that you don’t need to do this with Cloudflare. This is because in addition to being a CDN, Cloudflare is also a reverse proxy. So it intercepts all requests to your website and processes them through its servers – not just those for static content like images, JS, and CSS.

However, I recently found that Cloudflare’s cache hit rate was a bit too low for my liking. I found that even with page rules specifying long expire times, Cloudflare was requesting new content from my server when it shouldn’t have. In other words, my cache was being dropped for reasons unknown. Possibly because on the free tier, Cloudflare has far lower retention times for files than on higher tiers. In any case, Cloudflare doesn’t provide detailed traffic logs of cached or missed hits, so it’s up to us to do the analysis.

Wrong Approach: Redirecting URLs via .htaccess

Probably the easiest way to “rewrite” your URLs is to simply redirect them to the CDN pull zone via .htaccess. This should just take a couple of lines since all our assets are likely located in two folders – wp-content and wp-includes.

While this is easy to implement, it’s pretty inefficient since it involves an additional round trip for the client’s user agent. First to the origin server, then to the actual CDN. And the whole purpose of a CDN is to reduce latency. So using a redirect via .htacces or (worse) via a PHP script is a waste of resources.

Autoptimize is Insufficient

One of the most useful plugins for optimizing WordPress is Autoptimize. It’s hard for me to overstate its simplicity and power. In just one settings screen, it can combine and minify your CSS, Javascript, inline your CSS, and also make use a CDN to rewrite the newly generated CSS and JS files.

You can specify the CDN to use as shown here:

Specifying the CDN with Autoptimize

Unfortunately, this CND setting will not be used for other static assets like fonts and images. So while Autoptimize is a great tool, it’s not sufficient for everything. We still need to pair it with a dedicated plugin like Async Javascript and a separate CDN plugin.

Jetpack Site Accelerator – Nice, but Incomplete

I’ve also written about the benefits of the Jetpack Site Accelerator. It’s a CDN for your images and the CSS/JS files used by WordPress and WooCommerce. Very useful indeed! But it won’t cache non-WordPress assets. Meaning no files generated by Autoptimize, and the CSS/JS from other plugins. Until we have that functionality, I can’t recommend it.

Using CDN Enabler

Finally, I settled on the CDN Enabler plugin. This is developed by KeyCDN – one of the most popular and reliable CDN providers for everyday users. Once you download and install the plugin, enter your CDN URL as shown here:

CDN Enabler URL

After that, enable the following checkbox for HTTPS connections:

Enable HTTPS connections with CDN Enabler

In my opinion, the above option should be enabled by default – especially in today’s world. But right now, that’s what it is. This nifty plugin will replace all your static URLs in the specified folders. All CSS, Javascript, fonts, and images. It’s the only plugin I’ve found so far that’s an “all-in-one” solution like this.

If you’re a KeyCDN customer, you can also enter your API key and zone for manual purge requests from WordPress itself. But it’s not necessary. It works just fine with any CDN URL.

In my opinion, this is the most efficient way to rewrite all viable URLs with the respective CDN. If you have a better solution, let me know what you think!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Related Posts

Joomla vs. WordPress: Which One Is Better?

In this post, we’ll consider five differences between Joomla and WordPress and how you might go forward with setting up a WordPress website.

How To Start A Newsletter In WordPress

Check out our complete guide on why and how you should start your own newsletter in WordPress.

What Is Self-Hosted WordPress?

In this post, we’ll differentiate self-hosted WordPress from WordPress.com, and discuss the benefits of the former.

Blogger vs. WordPress: Which One to Use?

Let's compare WordPress and Blogger across five key areas. Then, we'll show you how to set up a professional blog with WordPress.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

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

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • OpenClaw Hosting
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • Managed VPS Hosting
  • Unmanaged VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • GPU Hosting
  • Email Hosting
  • HeroicGuard
  • Domains
  • Website Builder
  • AI Agent Hosting
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2026 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA