Can I redirect all traffic to https://www.* with a single page rule?

I don’t want to use Always Use HTTPS because it gets in the way of Cloudflare workers.

This page rule doesn’t work:

*example.com/*
Redirect
https://www.example.com/$2

It says it would cause an infinite redirect loop even though it wouldn’t actually because I have a higher priority page rule on https://www.example.com/*

May I ask if you have got both A www and A yourdomain.com (or CNAME?) records at your DNS dashboard?

What SSL option have you got selected under SSL tab/settings page for your domain?

Maybe this could help?:

I have both HSTS and Always Use HTTPS disabled.

I guess I should clarify my question. Can I redirect all traffic to https://www.* with a single page rule? I only know how to do it with two page rules which seems like a waste of a page rule. This page rule doesn’t work:

*example.com/*
Forwarding URL
https://www.example.com/$2

It says Forwarding URL matches the target and would cause a redirect loop. However it would not really cause a redirect loop because I have a higher priority page rule on https://www.example.com/*

I also have this problem. In fact, I actually used to have this exact page rule, but I think the validation must have updated because I cannot add it back. This is especially useful for redirecting multiple subdomains (m, ww1, etc) as well, which also can’t be done.

This doesn’t help me because I’m trying to do this with a page rule. But it might help you. Instead of a page rule you could use a Cloudflare worker:

addEventListener("fetch", event => {
	const request = event.request;
	const origin = "https://www.example.com/";// redirect all requests to this host
	if (request.url.slice(0, origin.length).toLowerCase()==origin) {// fetch requested URL
		event.respondWith(fetch(request));
	}
	else {// redirect request to new origin
		event.respondWith(new Response("", {status: 301, headers: {location: origin+request.url.split(/^https?:\/\/[^\/]+\//i)[1]}}));
	}
});

Then you have to add it to a Route on *example.com/*

1 Like

Thanks! I already do something like that, but I would like to use workers to accomplish this too.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.