Updated on 2023-03-30 GMT+08:00

How Do I Redirect Web Pages?

Scenarios

You can refer to the procedure below to do a 301 redirect.

Procedure

To do a 301 redirect on an ECS with the IIS installed, perform the following steps:
  1. Launch a website, for example, www.aaa.com, in the IIS.
  2. Create an empty folder on the disk.
  3. Create a website, for example, aaa.com, in the IIS and point it to the empty folder.
  4. On the home page, select HTTP Redirection and set parameters as follows:
    • Select Redirect requests to this destination.
    • Enter www.aaa.com$S$Q in the text box.

      The purpose of adding $S$Q to the end of a URL is to support redirection for a URL containing question marks (?).

    • Select Redirect all requests to exact destination (instead of relative to destination).
    • Set Status code to Permanent (301).
    Figure 1 HTTP Redirect

Helpful Links

In addition to redirection in the IIS, you can perform 301 redirects through code. The following describes how to perform 301 redirects in PHP and Apache.

  • 301 redirect in PHP
    <?php
    Header("HTTP/1.1 301 Moved Permanently");
    Header("Location: http//www.***.cn"); //Redirect to a URL with www.
    ?>
  • 301 redirect in Apache

    Example code for redirecting your domain to a www URL:

    deny from all
    RewriteEngine on
    RewriteCond %{HTTP_HOST}^(****\.com)(:80)?[NC]
    RewriteRule ^(.*) http://www.****.com/$1[R=301,L]
    order deny,allow