Skip to main content

Redirect

In Page Rules, you can redirect traffic sent to a specific URL to another address. To do this, go to CDN > Page Rules in the Arvancloud panel and click Add New Rule.

In the window that opens, enter the URL you want (such as www.example.com) in the address field. Next, select Redirect from the settings menu.

Now click the toggle next to Redirect to enable it, so you can set one of the codes 301, 302, or 307 for the address.

  • Code 301 (Permanent Redirect): This code is used when the goal is to permanently change one address to another. It tells search engines that the old URL has changed for good and that they should update their links to the new URL. If the old URL will still be used, a Temporary Redirect (302) should be used instead. For example, this code is recommended when the domain has changed completely but you want site visitors to still be able to reach the site with the old link.
  • Code 302: This code is mostly used for temporary redirects. It means the content was found but is in another location. If you plan to use the old URL in the future, or to temporarily send visitors from one address to another, use this code. In this case, the browser is directed to the new address, but search engines don't change their links to the new link.
  • Code 307: Works similarly to 302; the only difference is that in HTTP/1.1, code 307 is used for redirects instead of 302, because it guarantees that the method (in HTTP/1.0, where 302 was used for redirects, the method sometimes had to change from POST to GET) and the request body don't change during the redirect.

Then, in the address field of the redirect settings, enter the domain address you want the specified address to be redirected to, and click Add New Rule.

Advanced Redirect Settings​

A redirect with normal settings sends users to the desired page, but if the source URL has more than just the root domain, it has no effect on how users are redirected. For example, when a redirect sends the traffic of

Sample.com

to

Newsample.com

requests pointing to the page

Sample.com/example.html

are still redirected to

Newsample.com

whereas the desired result is redirecting the traffic to the page

Newsample.com/example.html

To prevent this, you need to use variables when defining page rules. To do this, go to CDN > Page Rules in the Arvancloud panel and click Add New Rule.

On the page that opens, enter the URL in the address field, then click the + sign to add a new rule, and in the menu that opens, click Redirect. Click the Redirect toggle to enable it and choose one of the three status codes 301, 302, or 307.

In the address field of the settings box, enter the address you want traffic redirected to. Note that to put a variable in any part of the address, simply use * in place of that part of the address. For example:

Sample.com/*
*.Sample.com
Sample.com/New/*.jpg

In the example above, the query string is not carried over from the source address to the destination.

In the destination address, use $ and a number to refer to the traffic's destination.

Newsample.com/$1

$1.Newsample.com

An address can also contain more than one variable.

*.Sample.com/*

In this case, $1 refers to the first variable, $2 to the second variable, and so on, with $n referring to the nth variable.

$1.newsample.com/$2

Finally, after making the settings, click Add New Rule to save the changes.

After this setup, if a user tries to open the page

Sample.com/example.html

they will be redirected to the page

Newsample.com/example.html