Redirect subdomains to another subdomain
If you want multiple subdomains pointing to the same subdomain or root domain, you can use Cloudflare to redirect the subdomains.
The domain or subdomain needs to be the default and already be configured. For a github page see Github Custom Domain to realize this.
In thie example the main subdomain is page.example.com and new redirected subdomains are pages.example.com and docs.example.com.
Steps
- Within cloudflare add a DNS Record for each subdomain you want to redirect.
In this example, we add two
Arecords forpages.example.comanddocs.example.compointing to the cloudflare ip192.0.2.1this allows cloudflare to add custom rules.pages.example.com. 1 IN A 192.0.2.1 ; cf_tags=cf-proxied:true docs.example.com. 1 IN A 192.0.2.1 ; cf_tags=cf-proxied:true
- In the cloudflare section for that domain goto
Rulesand add the following rule: - Redirect Rules
- Custom filter expression
- Field
HostnameOperatorwildcardValuepages.example.com - OR
- Field
HostnameOperatorwildcardValuedocs.example.com
- Field
- Then
- Wait a few minutes for the DNS records and rule to propagate.
- Done! Now you can access your Webpage with your two new custom domain.
pages.example.comanddocs.example.com
