mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2026-02-18 09:33:02 +08:00
feat(cloudflare) SINGLE_REDIRECT permits more than 301/302 redirects (#3514)
This commit is contained in:
parent
839d510b73
commit
14c3acb801
3 changed files with 14 additions and 14 deletions
12
commands/types/dnscontrol.d.ts
vendored
12
commands/types/dnscontrol.d.ts
vendored
|
|
@ -508,8 +508,8 @@ declare function CAA_BUILDER(opts: { label?: string; iodef: string; iodef_critic
|
|||
declare function CF_REDIRECT(source: string, destination: string, ...modifiers: RecordModifier[]): DomainModifier;
|
||||
|
||||
/**
|
||||
* `CF_SINGLE_REDIRECT` is a Cloudflare-specific feature for creating HTTP 301
|
||||
* (permanent) or 302 (temporary) redirects.
|
||||
* `CF_SINGLE_REDIRECT` is a Cloudflare-specific feature for creating HTTP redirects. 301, 302, 303, 307, 308 are supported.
|
||||
* Typically one uses 302 (temporary) or (less likely) 301 (permanent).
|
||||
*
|
||||
* This feature manages dynamic "Single Redirects". (Single Redirects can be
|
||||
* static or dynamic but DNSControl only maintains dynamic redirects).
|
||||
|
|
@ -518,16 +518,16 @@ declare function CF_REDIRECT(source: string, destination: string, ...modifiers:
|
|||
*
|
||||
* ```javascript
|
||||
* D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
|
||||
* CF_SINGLE_REDIRECT("name", 301, "when", "then"),
|
||||
* CF_SINGLE_REDIRECT('redirect www.example.com', 301, 'http.host eq "www.example.com"', 'concat("https://otherplace.com", http.request.uri.path)'),
|
||||
* CF_SINGLE_REDIRECT('redirect yyy.example.com', 301, 'http.host eq "yyy.example.com"', 'concat("https://survey.stackoverflow.co", "")'),
|
||||
* CF_SINGLE_REDIRECT("name", 302, "when", "then"),
|
||||
* CF_SINGLE_REDIRECT('redirect www.example.com', 302, 'http.host eq "www.example.com"', 'concat("https://otherplace.com", http.request.uri.path)'),
|
||||
* CF_SINGLE_REDIRECT('redirect yyy.example.com', 302, 'http.host eq "yyy.example.com"', 'concat("https://survey.stackoverflow.co", "")'),
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* The fields are:
|
||||
*
|
||||
* * name: The name (basically a comment, but it must be unique)
|
||||
* * code: Either 301 (permanent) or 302 (temporary) redirects. May be a number or string.
|
||||
* * code: Any of 301, 302, 303, 307, 308. May be a number or string.
|
||||
* * when: What Cloudflare sometimes calls the "rule expression".
|
||||
* * then: The replacement expression.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ parameter_types:
|
|||
"modifiers...": RecordModifier[]
|
||||
---
|
||||
|
||||
`CF_SINGLE_REDIRECT` is a Cloudflare-specific feature for creating HTTP 301
|
||||
(permanent) or 302 (temporary) redirects.
|
||||
`CF_SINGLE_REDIRECT` is a Cloudflare-specific feature for creating HTTP redirects. 301, 302, 303, 307, 308 are supported.
|
||||
Typically one uses 302 (temporary) or (less likely) 301 (permanent).
|
||||
|
||||
This feature manages dynamic "Single Redirects". (Single Redirects can be
|
||||
static or dynamic but DNSControl only maintains dynamic redirects).
|
||||
|
|
@ -26,9 +26,9 @@ Cloudflare documentation: <https://developers.cloudflare.com/rules/url-forwardin
|
|||
{% code title="dnsconfig.js" %}
|
||||
```javascript
|
||||
D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
|
||||
CF_SINGLE_REDIRECT("name", 301, "when", "then"),
|
||||
CF_SINGLE_REDIRECT('redirect www.example.com', 301, 'http.host eq "www.example.com"', 'concat("https://otherplace.com", http.request.uri.path)'),
|
||||
CF_SINGLE_REDIRECT('redirect yyy.example.com', 301, 'http.host eq "yyy.example.com"', 'concat("https://survey.stackoverflow.co", "")'),
|
||||
CF_SINGLE_REDIRECT("name", 302, "when", "then"),
|
||||
CF_SINGLE_REDIRECT('redirect www.example.com', 302, 'http.host eq "www.example.com"', 'concat("https://otherplace.com", http.request.uri.path)'),
|
||||
CF_SINGLE_REDIRECT('redirect yyy.example.com', 302, 'http.host eq "yyy.example.com"', 'concat("https://survey.stackoverflow.co", "")'),
|
||||
);
|
||||
```
|
||||
{% endcode %}
|
||||
|
|
@ -36,7 +36,7 @@ D("example.com", REG_MY_PROVIDER, DnsProvider(DSP_MY_PROVIDER),
|
|||
The fields are:
|
||||
|
||||
* name: The name (basically a comment, but it must be unique)
|
||||
* code: Either 301 (permanent) or 302 (temporary) redirects. May be a number or string.
|
||||
* code: Any of 301, 302, 303, 307, 308. May be a number or string.
|
||||
* when: What Cloudflare sometimes calls the "rule expression".
|
||||
* then: The replacement expression.
|
||||
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ func FromRaw(rc *models.RecordConfig, items []any) error {
|
|||
|
||||
name = items[0].(string)
|
||||
code = items[1].(uint16)
|
||||
if code != 301 && code != 302 {
|
||||
return fmt.Errorf("code (%03d) is not 301 or 302", code)
|
||||
if code != 301 && code != 302 && code != 303 && code != 307 && code != 308 {
|
||||
return fmt.Errorf("code (%03d) is not 301,302,303,307,308", code)
|
||||
}
|
||||
when = items[2].(string)
|
||||
then = items[3].(string)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue