mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-02-25 08:02:58 +08:00
CLOUDFLARE: Correct redirect function documentation (#696)
* expand on how Page Rules are handled * Correct Cloudflare redirect function documentation * add warning per discussion on #696
This commit is contained in:
parent
01b6669dfa
commit
5db21dcdec
3 changed files with 40 additions and 16 deletions
|
@ -5,12 +5,30 @@ parameters:
|
|||
- modifiers...
|
||||
---
|
||||
|
||||
`CF_REDIRECT` is the same as `CF_TEMP_REDIRECT` but generates a
|
||||
http 301 redirect (permanent redirect) instead of a temporary
|
||||
redirect.
|
||||
`CF_REDIRECT` uses Cloudflare-specific features ("Forwarding URL" Page Rules) to
|
||||
generate a HTTP 301 permanent redirect.
|
||||
|
||||
These redirects are cached by browsers forever, usually ignoring
|
||||
any TTLs or other cache invalidation techniques. It should be
|
||||
used with great care. We suggest using a `CF_TEMP_REDIRECT`
|
||||
initially, then changing to a `CF_REDIRECT` only after sufficient
|
||||
time has elapsed to prove this is what you really want.
|
||||
If _any_ `CF_REDIRECT` or `CF_TEMP_REDIRECT` functions are used then
|
||||
`dnscontrol` will manage _all_ "Forwarding URL" type Page Rules for the domain.
|
||||
Page Rule types other than "Forwarding URL” will be left alone.
|
||||
|
||||
WARNING: Cloudflare does not currently fully document the Page Rules API and
|
||||
this interface is not extensively tested. Take precautions such as making
|
||||
backups and manually verifying `dnscontrol preview` output before running
|
||||
`dnscontrol push`. This is especially true when mixing Page Rules that are
|
||||
managed by DNSControl and those that aren't.
|
||||
|
||||
HTTP 301 redirects are cached by browsers forever, usually ignoring any TTLs or
|
||||
other cache invalidation techniques. It should be used with great care. We
|
||||
suggest using a `CF_TEMP_REDIRECT` initially, then changing to a `CF_REDIRECT`
|
||||
only after sufficient time has elapsed to prove this is what you really want.
|
||||
|
||||
This example redirects the bare (aka apex, or naked) domain to www:
|
||||
|
||||
{% include startExample.html %}
|
||||
{% highlight js %}
|
||||
D("foo.com", .... ,
|
||||
CF_REDIRECT("mydomain.com/*", "https://www.mydomain.com/$1"),
|
||||
);
|
||||
{%endhighlight%}
|
||||
{% include endExample.html %}
|
||||
|
|
|
@ -5,13 +5,18 @@ parameters:
|
|||
- modifiers...
|
||||
---
|
||||
|
||||
`CF_REDIRECT` uses Cloudflare-specific features ("page rules") to
|
||||
generate an HTTP 301 redirect.
|
||||
`CF_TEMP_REDIRECT` uses Cloudflare-specific features ("Forwarding URL" Page
|
||||
Rules) to generate a HTTP 302 temporary redirect.
|
||||
|
||||
WARNING: If the domain has other pagerules in place, they may be
|
||||
deleted. At this time this feature is best used on bare domains
|
||||
that need to redirect to another domain, perhaps with wildcard
|
||||
substitutions.
|
||||
If _any_ `CF_REDIRECT` or `CF_TEMP_REDIRECT` functions are used then
|
||||
`dnscontrol` will manage _all_ "Forwarding URL" type Page Rules for the domain.
|
||||
Page Rule types other than "Forwarding URL” will be left alone.
|
||||
|
||||
WARNING: Cloudflare does not currently fully document the Page Rules API and
|
||||
this interface is not extensively tested. Take precautions such as making
|
||||
backups and manually verifying `dnscontrol preview` output before running
|
||||
`dnscontrol push`. This is especially true when mixing Page Rules that are
|
||||
managed by DNSControl and those that aren't.
|
||||
|
||||
{% include startExample.html %}
|
||||
{% highlight js %}
|
||||
|
|
|
@ -21,7 +21,7 @@ In the credentials file you must provide a [Cloudflare API token](https://dash.c
|
|||
}
|
||||
{% endhighlight %}
|
||||
|
||||
Make sure the token has at least the right read zones and edit DNS records (i.e. `Zone → Zone → Read` and `Zone → DNS → Edit`);
|
||||
Make sure the token has at least the right read zones and edit DNS records (i.e. `Zone → Zone → Read` and `Zone → DNS → Edit`; to modify Page Rules additionally requires `Zone → Page Rules → Edit`);
|
||||
checkout [Cloudflare's documentation](https://support.cloudflare.com/hc/en-us/articles/200167836-Managing-API-Tokens-and-Keys) for instructions on how to generate and configure permissions on API tokens.
|
||||
|
||||
|
||||
|
@ -142,7 +142,7 @@ will *not* automatically add it. You'll need to do that via the
|
|||
control panel manually or via the `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:
|
||||
The Cloudflare provider can manage "Forwarding URL" Page Rules (redirects) for your domains. Simply use the `CF_REDIRECT` and `CF_TEMP_REDIRECT` functions to make redirects:
|
||||
|
||||
{% highlight js %}
|
||||
|
||||
|
@ -169,3 +169,4 @@ 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.
|
||||
4. if _any_ `CF_REDIRECT` or `CF_TEMP_REDIRECT` functions are used then `dnscontrol` will manage _all_ "Forwarding URL" type Page Rules for the domain. Page Rule types other than "Forwarding URL” will be left alone.
|
||||
|
|
Loading…
Reference in a new issue