• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Startup Hero

The Official Blog Of Name Hero

Learn To Fly Above The Competition Get Started
  • HomeWelcome
  • CoursesVideo Training Center
  • About UsWhat is StartupHero?
  • BlogGet the latest
  • Start HereStartup 101
  • SpeakingPodcast & Media
  • ResourcesTools to help You
    • Reselling WordPress Hosting
    • Resell Hero
    • How To Start A Blog
  • NameHeroCloud Web Hosting

Use Cloudflare To Change Response Headers

By Bhagwad Park on October 10, 2022 0

Use Cloudflare To Change Response Headers

Response headers can be notoriously difficult to change. Particularly if you’re using a CMS like WordPress, it’s often a mystery where certain response headers are coming from. Cache-control is a great example of where many WordPress developers have torn their hair out in frustration, trying to figure out which plugin or .htaccess rule is setting it. Luckily, with Cloudflare, you can now easily change response headers for any subset of your URLs which just a few clicks.

Previously Used Workers to Set Response Headers

Before this tool became fully operational, I recommended Cloudflare workers to set response headers. A great use case was the X-Robots-Tag response header, which Google now requires for all “noindex” pages. I wrote an earlier tutorial on how to add an X-Robots-Tag response header to affiliate links using Cloudflare workers. This was the solution I used on my site WP-Tweaks.com.

Unfortunately, Workers came with some drawbacks. For one, you only got a limited number of worker calls for free. The free limit is generous, but you never know when you might hit the limit. The second (more serious) limitation is that the workers interfere with my bulk redirects, so I can either use workers for the X-Robots-Tag or give up Cloudflare’s bulk redirects.

But thanks to transform rules, I don’t need to make that choice anymore.

How to Use Cloudflare Transform Rules to Set Response Headers

To set the response header, transform rules on Cloudflare, log in and click “Rules,” and then Transform rules as shown here:

Cloudflare Transform Rules
Cloudflare Transform Rules

This will open the “Transform Rules” configuration screen, where you can modify the request headers, rewrite the URL, or change the response headers. We’re interested in the response headers, so click “Create Transform Rule” and choose “Modify Response Header,” as shown here:

Cloudflare Modify Response Header
Cloudflare Modify Response Header

In the response header modification screen, configure your response headers like this:

Adding an X-Robots-Tag Response Header with Cloudflare
Adding an X-Robots-Tag Response Header with Cloudflare

In the above screenshot, I’ve configured all affiliate links with the URL pattern “/recommends/” to have an X-Robots-Tag. I’ve used Cloudflare’s URI matching field to match a set of URLs and the “Set static” response header because I just need to set a simple value with no additional rules.

Save your changes, and you’re done!

Cloudflare Transform Rules Free Tier Limits

For the Cloudflare free tier, you get 10 free transform rules. This limit is more than enough for a free account, and it’s doubtful you’ll ever need to use more than that. Pro accounts get 25 rules. This includes request header changes and URL rewrites, but even so, it’s more than most websites need.

The benefit of using workers is that there’s no traffic limit to which these rules apply. As long as you stay below the total number of transform rules, you’re good, unlike with workers, where you need to keep an eye on the number of times they execute.

Use Transform Rules for cache-control As Well

I find using transform rules works well for complicated settings like cache control. Instead of using a WordPress plugin and adding to the burden of your site, just use Cloudflare’s transform rule for a set of websites, so you don’t need to worry about systems not caching your pages. I’d written earlier about the pros and cons of advertisements on your site. Ezoic is one of the most popular ad networks, and their systems won’t cache content to speed things up if you have an incorrectly configured cache-control or “Vary” header. You can use Cloudflare transform rules to solve all these problems.

Cloudflare keeps improving its products and offering new services. If QUIC.cloud aims to be a proper competitor, they’d better catch up fast!

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!

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

Connect With Us!

Superhero Resources

Fix Common Issues

  • How To Setup Free And Automatic SSL Certificates
  • How To Setup Cloudflare With Railgun
  • How To Fix Memory Exhausted Errors In WordPress
  • How To Edit PHP Version/Upload Limit/Add Extensions
  • How To Move/Migrate Your Business To Name Hero

Free Guides

  • How To Setup NameHero Hosting
  • How To Create A Web Hosting Business With WordPress
  • How To Start A WordPress Blog
  • How To Migrate WordPress To A VPS
  • How To Speed Test And Optimize Your WordPress Website
  • Magento 2.X Installation Guide
  • How To Clean Up A WordPress Hack

Training

Recent Posts

  • The Best WordPress Plugin To Combat Plagiarism
  • Is It Time to Bring Back Blog Comments?
  • Two Filters That No Longer Work In Gutenberg (And Workarounds)
  • Migrating To The New Cloudflare Managed Rules Interface
  • How To Sort Posts By The “Last Modified” Date
  • How To Make WordPress Send E-mail From Another Address
Subscribe in a reader
  • Web Hosting
  • WordPress Hosting
  • Reseller Hosting
  • VPS Hosting
  • Twitter
  • Facebook
  • LinkedIn
  • YouTube
  • FTC Disclosure
  • Earnings Disclosure
  • Privacy Policy

Copyright © 2023 · Smart Passive Income Pro on Genesis Framework · WordPress · Log in