From dc283df76dc3a04486122a09402469e2550e3925 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Fri, 15 Mar 2024 07:44:16 -0700 Subject: [PATCH] Redirecting a whole domain with Cloudflare --- cloudflare/redirect-whole-domain.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 cloudflare/redirect-whole-domain.md diff --git a/cloudflare/redirect-whole-domain.md b/cloudflare/redirect-whole-domain.md new file mode 100644 index 0000000000..ca73120057 --- /dev/null +++ b/cloudflare/redirect-whole-domain.md @@ -0,0 +1,20 @@ +# Redirecting a whole domain with Cloudflare + +I had to run this site on `til.simonwillison.org` for 24 hours due to a domain registration mistake I made. + +Once I got `til.simonwillison.net` working again I wanted to permanently redirect the URLs on the temporary site to their equivalent on the correct domain. + +Since I was running the site behind [Cloudflare](https://www.cloudflare.com/), I could get Cloudflare to handle the redirects for me using a Page Rule, which support wildcards for redirects. + +I used these settings: + +- URL: `til.simonwillison.org/*` +- Setting: Forwarding URL +- Status code: 301 (permanent redirect) +- Destination URL: `https://til.simonwillison.net/$1` + +This did the right thing - hits to e.g. https://til.simonwillison.org/cloudflare?a=1 redirect to https://til.simonwillison.net/cloudflare?a=1 + +Here's a screenshot of the settings page I used to create the new Page Rule: + +![Screenshot of the Cloudflare interface. Create a Page Rule for simonwillison.org. If the URL matches: URL (required) til.simonwillison.org/* Then the settings are: Forwarding URL https://til.simonwillison.net/$1 Select status code (required) 301 - Permanent Redirect. Save and Deploy Page Rule](https://github.com/simonw/til/assets/9599/6758a865-57fa-4da1-9e41-118f41e1d7b2)