Redirecting requests
You can customize redirection of requests from a CDN resource to an origin by changing the URIRewrite
rule.
For example, you can use this option to reconfigure content request paths if the file and folder structure of the origin has changed. You can also use redirection if you want to keep search engine rankings of your content when moving your resource to a new address.
You can enable request redirection for a CDN resource using the management console
To configure request redirection, you need to set a rewrite rule and specify a flag.
For more information about redirecting requests, see the documentation of the EdgeCenter CDN provider:
Rewrite rule
A rewrite rule must contain two space-separated directives:
-
Source path: URI part to replace. It is specified as a regular expression
.Regular expression parts can be placed in brackets. In this case, the URI parts mapped to such expression parts will be available in the edited path in the values of the
$1
,$2
, ...$9
variables, where the variable number matches the sequence number of the regular expression part in the source path. -
Edited path: URI part that must replace the original path matching the specified regular expression.
In the edited path, you can use variables containing parts of the source path which have been placed in brackets:
$1
,$2
, ...$9
.
Rewrite rule example:
/(videos)/(events)/(\d{4}-\d{2}-\d{2})/(.*) /$2/$1/$3-$4
This rule will modify the request URI as follows:
Source URI:
https://example.com/videos/events/2024-01-01/new-year.avi
Target URI:https://example.com/events/videos/2024-01-01-new-year.avi
Flag
Flags allow you to stop further processing of Rewrite
directives or return redirect
to the user. The following flags are available for Rewrite
rules:
break
: Terminates the processing of the current set of directives.last
: Terminates the processing of the current set of directives and starts searching for a new CDN server that matches the new URI.redirect
: Returns a temporaryredirect
with the302
status code to the user. This flag is used if the replacement string does not start withhttp://
,https://
, or$scheme
.permanent
: Returns a permanentredirect
with the301
status code to the user.