Website 301 redirect How to set

Source: Internet
Author: User

To do site optimization, we basically know that URL standardization needs to adopt 301 redirect. Redirection is a straightforward point, that is, by means of various network requests to redirect the direction to other locations, that is, usually said, the page jump. So how do you set up and make 301 redirects? Here are a few more common scenarios:

Steps/Methods

  1. The first: Set up 301 redirect methods for multiple pages throughout the site

    If you want to set the entire site 301 Redirect, it is recommended that you create a separate 301.php, the file name can be taken. The code is as follows:

    <?php

    $the _host = $_server[' http_host '); Get access to the domain name entered [URL: like www.siyuan-seo.com]

    $the _url = isset ($_server[' Request_uri ')? $_server[' Request_uri ': '; Determine the back part of the address

    $the _url = strtolower ($the _url); Turn the English letter into lowercase

    if ($the _url== "/index.php")//judgment is not home

    {

    $the _url= ""; If it is the first page, the assignment is empty

    }

    if ($the _host!== ' www.icoa.cn ')//If the domain name is not a URL with www then proceed to the following 301 jump

    {

    Header (' http/1.1 301 Moved permanently '); Issue 301 Head

    Header (' location:http://www.siyuan-seo.com '. $the _url); Jump to the URL with www

    }

    ?>

    Note: The code if ($the _host!== ' www.siyuan-seo.com ') in the "!==" is not exactly equal to the meaning, you can also use "! =" does not mean that, in addition to the siyuan-seo.com can be redirected to the URL with www, You can also put all the www.siyuan-seo.com that bind to the domain name of this space jump.

    301.php file after writing, with the FTP software uploaded to the root directory of the Web site, generally is the Web file. So how do you call it? It's very simple, actually.

    Call 301.php in the page where you need to set 301 redirects, code: <?php include ("301.php"); 301 redirect?> Put this code at the front of all your pages, so you're done. Such as:

  2. 2

    The second type: Web site single Page Setup 301 Redirect method

    If just a single page in the site for 301 redirect settings, it is very simple, as long as the PHP page in the head with the following two lines of code can be:

    <?php

    Header ("http/1.1 301 Moved permanently");

    Header ("location:http://www.siyuan-seo.com");

    ?> such as:


    In fact, most of the cases, we generally do not need to set 301 Redirect, the use of the situation is very few, we know how to do it.

  

Website 301 redirect How to set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.