Example Rules

Previous Next

Example Rules


Access Control

You can limit access to your content by defining rules within the <visit-control-rules> of your domain's configuration. Here are several examples that may help you define rules needed by your domains.  Please refer to the domain creation API for further information on the related XML tags.


Requirement

XML Configuration

If User-Agent header value includes “Google” , then block the request. Other requests are allowed.

<visit-control-rules>

<visit-control-rule>

<path-pattern>/*</path-pattern>

<allowed-header-name>User-agent</allowed-header-name>

<forbidden-header-value>*Google*</forbidden-header-value>

</visit-control-rule>

</visit-control-rules>

If User-Agent header value includes “IE” , then the request is allowed. All other requests are blocked.

<visit-control-rules>

<visit-control-rule>

<path-pattern>/*</path-pattern>

<allowed-header-name>User-agent</allowed-header-name>

<allowed-header-value>*IE*</allowed-header-value>

</visit-control-rule>

</visit-control-rules>

If the request is from 1.1.1.1, and “IE” does not appear in the User-agent header value, then it is blocked. Other requests are allowed.

<visit-control-rules>

<visit-control-rule>

<path-pattern>/*</path-pattern>

<forbidden-ips>1.1.1.1</forbidden-ips>

<allowed-header-name>User-agent</allowed-header-name>

<allowed-header-value>*IE*</allowed-header-value>

</visit-control-rule>

</visit-control-rules>

If the request is from 1.1.1.1 and “Google” appears in the User-agent header value, then it is blocked. Other requests are allowed.

<visit-control-rules>

<visit-control-rule>

<path-pattern>/*</path-pattern>

<forbidden-ips>1.1.1.1</forbidden-ips>

<allowed-header-name>User-agent</allowed-header-name>

<forbidden-header-value>*Google*</forbidden-header-value>

</visit-control-rule>

</visit-control-rules>

If the request is from 1.1.1.1, the client is in the United States or China, and it  “Google” appears in the User-Agent header, then the request is blocked. Other requests are allowed.



<visit-control-rules>

<visit-control-rule>

<path-pattern>/*</path-pattern>

<forbidden-ips>1.1.1.1</forbidden-ips>

<forbidden-area>US;CN</forbidden-area>

<allowed-header-name>User-agent</allowed-header-name>

<forbidden-header-value>*Google*</forbidden-header-value>

</visit-control-rule>

</visit-control-rules>


Rewriting URLs

You can rewrite URLs and redirect requests defining <rewrite-rule-settings> element in your domain's configuration. Here are several examples that may help you define rules needed by your domains. Please refer to the domain creation API for further information on the related XML tags.


Requirement

XML Configuration

Rewrite URL and protocol, doing a 301 redirect


Redirect http://source.quantil.com/*  to https://destination.quantil.com/*



<rewrite-rule-settings>

<rewrite-rule-setting>

<path-pattern>*</path-pattern>

<rewrite-type>url</rewrite-type>

<rewrite-method>301</rewrite-method>

<before-value>http://source.quantil.com/*</before-value>

<after-value>https://destination.quantil.com/*</after-value>

<ignore-query-string>false</ignore-query-string>

</rewrite-rule-setting>

</rewrite-rule-settings>

Redirect http://source.quantil.com/*/games/marvel-roulette to http://source.quantil.com/games/roulette

rewrite-rule-settings>

<rewrite-rule-setting>

<path-pattern>*</path-pattern>

<rewrite-type>url</rewrite-type>

<rewrite-method>302</rewrite-method>

<before-value>http://source.quantil.com/*/games/marvel-roulette</before-value>

<after-value>http://source.quantil.com/games/roulette</after-value>

<ignore-query-string>false</ignore-query-string>

</rewrite-rule-setting>

</rewrite-rule-settings>

Rewrite the URL and protocol, keeping query strings


Redirect http://source.quantil.com/us/a?id=123456789&type=abcd  

to

https://target.quantil.com/cn/a?id=123456789&type=abcd


(Remember to escape ‘&’ as “&amp;” in the XML fields)



<rewrite-rule-settings>

<rewrite-rule-setting>

<path-pattern>*</path-pattern>

<rewrite-type>url</rewrite-type>

<rewrite-method>302</rewrite-method>

<before-value>http://source.quantil.com/us/a?id=123456789&amp;type=abcd</before-value>

<after-value>https://target.quantil.com/cn/a?id=123456789&amp;type=abcd</after-value>

<ignore-query-string>false</ignore-query-string>

</rewrite-rule-setting>

</rewrite-rule-settings>

Rewrite URL and protocol, removing query strings


Redirect http://source.quantil.com/us/a?id=123456789&type=abcd  

to https://target.quantil.com/cn/



<rewrite-rule-settings>

<rewrite-rule-setting>

<path-pattern>*</path-pattern>

<rewrite-type>url</rewrite-type>

<rewrite-method>302</rewrite-method>

<before-value>http://source.quantil.com/us/a?id=123456789&amp;type=abcd</before-value>

<after-value>https://target.quantil.com/cn/</after-value>

<ignore-query-string>true</ignore-query-string>

</rewrite-rule-setting>

</rewrite-rule-settings>

1. If client is a cell phone (user agent is “Phone” or “iPhone”) and the client is from China or Spain, then redirect from http://source.quantil.com/

to

http://m.target.quantil.com/spain/object



2. If client is a PC from Germany, redirect  http://source.quantil.com/

to

http://pc.target.quantil.com/Germany/object



<rewrite-rule-settings>

<rewrite-rule-setting>

<path-pattern>*</path-pattern>

<rewrite-uas>*Phone*;*iPhone*</rewrite-uas>

<rewrite-area>CN;ES</rewrite-area>

<rewrite-type>url</rewrite-type>

<rewrite-method>302</rewrite-method>

<before-value>http://source.quantil.com/</before-value>

<after-value>http://m.target.quantil.com/spain/object</after-value>

<ignore-query-string>false</ignore-query-string>

</rewrite-rule-setting>

<rewrite-rule-setting>

<path-pattern>*</path-pattern>

<rewrite-uas>*Windows*;*Macintosh*</rewrite-uas>

<rewrite-area>DE</rewrite-area>

<rewrite-type>url</rewrite-type>

<rewrite-method>302</rewrite-method>

<before-value>http://source.quantil.com/</before-value>

<after-value>http://pc.target.quantil.com/spain/object</after-value>

<ignore-query-string>false</ignore-query-string>

</rewrite-rule-setting>

</rewrite-rule-settings>


Changing Protocols

You can switch between HTTP and HTTPS protocols by defining <rewrite-rule-settings> element in your domain's configuration. Here are several examples that may help you define rules needed by your domains. Please refer to the domain creation API for further information on the related XML tags.


Requirement

XML Configuration

Force use of HTTP when responding to visitors

<rewrite-rule-settings>

<rewrite-rule-setting>

<path-pattern>*</path-pattern>

<rewrite-type>protocol</rewrite-type>

<before-value>https</before-value>

<after-value>http</after-value>

<rewrite-method>302</rewrite-method>

</rewrite-rule-setting>

</rewrite-rule-settings>

Force use of HTTPS when responding to visitors

<rewrite-rule-settings>

<rewrite-rule-setting>

<path-pattern>*</path-pattern>

<rewrite-type>protocol</rewrite-type>

<before-value>http</before-value>

<after-value>https</after-value>

<rewrite-method>302</rewrite-method>

</rewrite-rule-setting>

</rewrite-rule-settings>



Custom Origin Rules

Custom origin rules can be created to control how requests to your origin servers are made from the CDN servers. Please refer to the domain creation API for further information on the related XML tags.

Requirement

XML Configuration

Remove query strings include “_escaped_fragment_” and add ”.htm” to the URL for requests from our cache back to your origin.

<origin-rules>

<origin-rule>

      <path>/*?*_escaped_fragment_*</path>

      <ignore-case>true</ignore-case>

      <origin-ips>target.quantil.com</origin-ips>

      <modified-option>1</modified-option>

      <modified-path>/*.htm</modified-path>

</origin-rule>

<origin-rules>