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
    • All guides
    • Connecting to a Cloud CDN provider
      • Creating a resource
      • Editing basic settings of a resource
      • Getting information about a resource
      • Configuring resource caching
      • Configuring log export
      • Pre-loading files to CDN servers
      • Purging resource cache
      • Configuring request and response headers
      • Configuring CORS for responses to clients
      • Configuring HTTP methods
      • Enabling file compression
      • Enabling file segmentation
      • Enabling origin shielding
      • Configuring request redirection
      • Setting up access via a secure token
      • Managing additional resource settings
      • Disabling a resource
      • Managing resource labels
      • Deleting a resource
      • Viewing resource statistics
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes
  • Troubleshooting
  1. Step-by-step guides
  2. Resources
  3. Configuring request redirection

Configuring request redirection

Written by
Yandex Cloud
Updated at May 13, 2025

With request redirection, you can reconfigure paths of requests to your content. This can be useful when restructuring files and folders on an origin. You can also use redirection if you want to keep search engine rankings of your content when moving your resource to a new address.

To enable request redirection on a CDN resource:

Management console
CLI
API
  1. In the management console, select the folder where your resource is located.

  2. Select Cloud CDN.

  3. Click the CDN resource name.

  4. In the top-right corner, click Edit.

  5. Enable Redirect requests.

  6. In the Rewrite rule field, set a rule, e.g., /(.*) /new-folder/$1.

    A rewrite rule must contain two space-separated directives: the original path you need to replace, and the edited path, which replaces the original path.

    You can use regular expressions in the rule. For more information, see Rewrite rule.

  7. In the Flag field, specify the required flag:

    • 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.
  8. Click Save.

If you do not have the Yandex Cloud (CLI) command line interface yet, install and initialize it.

The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

  1. View the description of the CLI update resource command:

    yc cdn resource update --help
    
  2. Get a list of all resources in the default folder:

    yc cdn resource list --format yaml
    

    Result:

    - id: bc8ceo77zu7h********
      folder_id: b1gt6g8ht345********
      cname: cdn.example.com
      created_at: "2024-09-10T19:15:16.305043Z"
      updated_at: "2024-09-11T17:19:50.622628Z"
      active: true
      options:
        edge_cache_settings:
          enabled: true
          default_value: "345600"
        query_params_options:
          ignore_query_string:
            enabled: true
            value: true
        slice:
          enabled: true
          value: true
        host_options:
          host:
            enabled: true
            value: cdn-source-sample-bucket.storage.yandexcloud.net
        stale:
          enabled: true
          value:
            - error
            - updating
        ignore_cookie:
          enabled: true
          value: true
      origin_group_id: "328146"
      origin_group_name: Origins for cdn.example.com (225300)
      origin_protocol: HTTPS
      ssl_certificate:
        type: CM
        status: READY
        data:
          cm:
            id: fpquvh0em4no********
    

    Save the CDN resource ID (the id field at the beginning of the output) as you will need it at the next step.

  3. Enable request redirection by specifying the CDN resource ID you saved in the previous step:

    yc cdn resource update <resource_ID> \
      --rewrite-body '<rewrite_rule>' \
      --rewrite-flag <flag>
    

    Where:

    • --rewrite-body: Rewrite rule, e.g., --rewrite-body '/(.*) /new-folder/$1'.

      A rewrite rule must contain two space-separated directives: the original path you need to replace, and the edited path, which replaces the original path.

      You can use regular expressions in the rule. For more information, see Rewrite rule.

    • --rewrite-flag: Flag. The possible values are:

      • 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.
    Result
    id: bc8ceo77zu7h********
    folder_id: b1gt6g8ht345********
    cname: cdn.example.com
    created_at: "2024-09-10T19:15:16.305043Z"
    updated_at: "2024-09-11T17:55:21.100567Z"
    active: true
    options:
      edge_cache_settings:
        enabled: true
        default_value: "345600"
      query_params_options:
        ignore_query_string:
          enabled: true
          value: true
      slice:
        enabled: true
        value: true
      host_options:
        host:
          enabled: true
          value: cdn-source-sample-bucket.storage.yandexcloud.net
      stale:
        enabled: true
        value:
          - error
          - updating
      ignore_cookie:
        enabled: true
        value: true
      rewrite:
        enabled: true
        body: /(.*) /new-folder/$1
        flag: BREAK
    origin_group_id: "328146"
    origin_group_name: Origins for cdn.example.com (225300)
    origin_protocol: HTTPS
    ssl_certificate:
      type: CM
      status: READY
      data:
        cm:
          id: fpquvh0em4no********
    

    To disable request redirection for a CDN resource, run this command by specifying the CDN resource ID:

    yc cdn resource update <resource_ID> --clear-rewrite
    

    For more information about the yc cdn resource update command, see the CLI reference.

Use the update REST API method for the Resource resource or the ResourceService/Update gRPC API call.

It may take up to 15 minutes for the new settings of the existing resource to apply to CDN servers. After that, we recommend purging the resource cache.

See also

  • Redirecting requests

Was the article helpful?

Previous
Enabling origin shielding
Next
Setting up access via a secure token
Yandex project
© 2025 Yandex.Cloud LLC