If someone types anything after the slash in my domain, can I make it redirect to my main website?

Hi all. I currently own a domain that I'm using as a CDN with Cloudflare's R2 service.I was wondering if I can make some sort of rule where no matter what anyone types after the slash in the CDN domain, it'll redirect to my main site? I can get this to work if people go to the CDN domain without the slash, but if I type something random after the slash, it'll take me to a "Not Found" page, that comes from Cloudflare R2. Is what I'm achieving possible? Please let me know. Thanks.
5 Replies
Chaika
Chaikaā€¢11mo ago
Your main site is on a different domain? Do you want to avoid redirecting if the file exists? You could use a simple redirect rule to match everything, but it would fire even if an asset exists on that url
Casper
Casperā€¢11mo ago
my main site is hosted on neocities, and yes iā€™d like to avoid redirecting if the file exists
Chaika
Chaikaā€¢11mo ago
Then you'd have to use a Worker (would also be a good case for Snippets whenever they come out), can't easily do it with anything else Problem is using a Worker is you'd pay for every single request as an invocation, and Workers run in front of cache so even for cached requests you'd be paying something. If your website is Pro or above you could use these: https://developers.cloudflare.com/rules/custom-error-responses/, and just have a meta refresh/js refresh in the html. A bit hacky and would require Pro
Casper
Casperā€¢11mo ago
thank you for the information šŸ‘
Erisa
Erisaā€¢11mo ago
You can probably handle this on the neocities side by editing your 404 page (https://thewikion.neocities.org/wiki/404) to have a meta refresh redirecting to the main website With meta refresh being this thing https://www.w3.org/TR/WCAG20-TECHS/H76.html
Want results from more Discord servers?
Add your server