1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Cloudflare Redirects (#119)

* function sig

* sig

* some custom record infrastructure

* CLOUDFLARE REDIRECTS!

* comments out

* guarding redirects behind provider metadata to manage

* catch commas in js to ensure proper encoding.

* gen

* small fix

* revendor otto

* docs
This commit is contained in:
Craig Peterson
2017-05-19 14:15:57 -04:00
committed by GitHub
parent a355b8e438
commit f1a0d65198
18 changed files with 471 additions and 99 deletions

View File

@@ -22,13 +22,14 @@ username and access token:
## Metadata
Record level metadata availible:
* cloudflare_proxy ("on", "off", or "full")
* `cloudflare_proxy` ("on", "off", or "full")
Domain level metadata availible:
* cloudflare_proxy_default ("on", "off", or "full")
* `cloudflare_proxy_default` ("on", "off", or "full")
Provider level metadata availible:
* ip_conversions
* `ip_conversions`
* `manage_redirects`: set to `true` to manage page-rule based redirects
## Usage
@@ -55,3 +56,31 @@ If a domain does not exist in your CloudFlare account, DNSControl
will *not* automatically add it. You'll need to do that via the
control panel manually or via the command `dnscontrol create-domains`
-command.
## Redirects
The cloudflare provider can manage Page-Rule based redirects for your domains. Simply use the `CF_REDIRECT` and `CF_TEMP_REDIRECT` functions to make redirects:
{% highlight js %}
// chiphacker.com is an alias for electronics.stackexchange.com
D("chiphacker.com", REG_NAMECOM, DnsProvider(CFLARE),
// must have A records with orange cloud on. Otherwise page rule will never run.
A("@","1.2.3.4", CF_PROXY_ON),
A("www", "1.2.3.4", CF_PROXY_ON)
A("meta", "1.2.3.4", CF_PROXY_ON),
// 302 for meta subdomain
CF_TEMP_REDIRECT("meta.chiphacker.com/*", "https://electronics.meta.stackexchange.com/$1),
// 301 all subdomains and preserve path
CF_REDIRECT("*chiphacker.com/*", "https://electronics.stackexchange.com/$2),
);
{%endhighlight%}
Notice a few details:
1. We need an A record with cloudflare proxy on, or the page rule will never run.
2. The IP address in those A records may be mostly irrelevant, as cloudflare should handle all requests (assuming some page rule matches).
3. Ordering matters for priority. CF_REDIRECT records will be added in the order they appear in your js. So put catch-alls at the bottom.