Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Cloud CDN
  • Getting started
    • Service overview
    • Resource
    • Origins and origin groups
    • Redirecting requests
    • Content caching
    • Secure tokens
    • IP-based access policy
    • Log export
    • Labels
    • Quotas and limits
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes
  • Troubleshooting

In this article:

  • Rewrite rule
  • Flag
  • Use cases
  1. Concepts
  2. Redirecting requests

Redirecting requests

Written by
Yandex Cloud
Updated at April 10, 2025
  • Rewrite rule
  • Flag
  • Use cases

You can customize redirection of requests from a CDN resource to an origin by changing the URI of the request using a Rewrite 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, CLI, or API.

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. Configuring request redirection
  • API documentation

Rewrite ruleRewrite 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

FlagFlag

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 temporary redirect with the 302 status code to the user. This flag is used if the replacement string does not start with http://, https://, or $scheme.
  • permanent: Returns a permanent redirect with the 301 status code to the user.

Use casesUse cases

  • Enabling a blue-green and canary deployment of web service versions
  • Migrating to Yandex Cloud CDN from a third-party CDN provider

See alsoSee also

  • Guide for enabling request redirection

Was the article helpful?

Previous
Origin shielding
Next
Content caching
Yandex project
© 2025 Yandex.Cloud LLC