Free tool
Cloudflare Rules Generator
Write Cloudflare rule expressions for redirects, user-agent blocks, forced HTTPS and bulk redirect lists.
How it works
What is the Cloudflare Rules Generator?
The Cloudflare Rules Generator is a free tool that writes Cloudflare rule expressions for four common jobs: redirecting a path, blocking or challenging a user agent, forcing HTTPS, and preparing a bulk redirect list from CSV rows. It outputs the expression in the Rules language and tells you where in the dashboard to paste it.
How to use the Cloudflare Rules Generator
- Choose the rule type: redirect a path, block a user agent, force HTTPS or bulk redirects.
- Fill in the fields, such as the hostname, path and target URL, or the user-agent tokens.
- Copy the rule expression.
- Follow the listed steps to paste it into the right part of the Cloudflare dashboard.
What is a Cloudflare rule expression?
Cloudflare rules have two parts: an expression that decides which requests match, and an action. Expressions are written in the Rules language, which compares request fields to values, for example http.request.uri.path eq "/old".
The dashboard has a visual builder, but every rule screen also offers an Edit expression link where you can paste text directly. That is where the output of this tool goes.
Which fields and functions does the generator use?
A deliberately small, documented subset: http.host for the hostname, http.request.uri.path for the path without the query string, http.user_agent for the user-agent header, ssl for whether the request used HTTPS, and http.request.full_uri for bulk redirect lists. Comparisons use eq, contains, in and the starts_with() function, joined with and, or and not.
Keeping to this subset means the expressions work on every plan. Regex matching, for instance, needs a paid plan, so the tool does not use it.
How do I redirect a URL in Cloudflare?
For one path or a path prefix, use a Redirect Rule. Paste the expression as the custom filter, set the redirect type to Static, enter the target URL and choose 301 or 302. Path equals matches one URL; path starts with matches a whole section and sends everything to the single target.
For many one-to-one redirects, use Bulk Redirects. The tool cleans your source,target,status rows into the CSV Cloudflare imports. Sources must include the hostname, and the allowed status codes are 301, 302, 307 and 308. Check the mapping for chains first with the Redirect Map Generator.
How do I block a bot by user agent in Cloudflare?
Create a WAF custom rule with an expression such as http.user_agent contains followed by the bot's token in quotes, and pick Block or Managed Challenge as the action. Several tokens are joined with or. The contains operator is case-sensitive, so the token has to match the header's casing.
Unlike robots.txt, this is enforced at the edge: the request never reaches your server. A bot can still change its user agent, so it stops honest crawlers and lazy scrapers, not determined ones. For the polite route, write rules with the AI Crawler Robots.txt Generator.
How do I force HTTPS in Cloudflare?
The simplest way is the Always Use HTTPS setting under SSL/TLS, Edge Certificates, which redirects every HTTP request for the zone. Use a rule only when you want it for one hostname. The generator writes not ssl as the match and a dynamic target built with concat() from the host and path, with a 301.
Cloudflare renames and moves dashboard menus from time to time, so a menu name in the steps may differ slightly from what you see. Rule quotas also vary by plan. If your origin is Apache or nginx and you would rather redirect there, use the .htaccess Redirect Generator.
Questions
- Does this tool change my Cloudflare account?
- No. It only writes text. Nothing is sent to Cloudflare, and the expressions are not checked against your zone.
- What is the difference between a Redirect Rule and Bulk Redirects?
- A Redirect Rule matches requests with an expression and belongs to one domain. Bulk Redirects are account-level lists of exact source and target URLs, built for large numbers of static redirects.
- Does the path field include the query string?
- No.
http.request.uri.pathholds the path only. The tool warns if you type a query string into the path. - Should I block or challenge a bot?
- Block refuses the request outright. Managed Challenge lets Cloudflare decide whether to show a challenge, which is safer when real visitors might share the pattern.
- Is the Cloudflare Rules Generator free?
- Yes, with a free spyc.ai account. It runs in your browser, so nothing you type or paste is sent to a server.
Technical SEO Tools
More in Technical SEO Tools
Opengraph Viewer
Paste a URL and see the card it produces when someone shares it — title, description, image.
View OpengraphOpen Graph Generator
Write the Open Graph tags, preview the card, copy the markup.
Generate Open Graph tagsRobots.txt Checker
Fetch any site's robots.txt and test one URL against it: allowed, or blocked by which rule.
View robots.txtReady when you are
Before your next buyer asks AI about you, ask AI about yourself
One check, four engines, about twenty seconds. We show you the answers before we ask for anything.