PHP Tutorial: How to Achieve 301 redirects

Source: Internet
Author: User
Tags php code php tutorial

What is a 301 redirect? 301 redirect is when your site address changes, such as changing the domain name, website revision, etc., you want visitors or search engines to jump to a new address to visit the site, then you need to do 301 redirect. There are many ways to achieve 301 redirects, this article mainly describes how to achieve 301 redirect PHP program.

    implement 301 redirect PHP code

    <?php

    $the _h ost = $_server[' Http_host '];  //Mark gets the current domain name

    $request _url = isset ($_server[' Request_uri '])? $_server[' Request_uri ']: ';  //The following section of the address

    if ($the _host!== ' www.3lian.com ") & nbsp;//has not replaced the domain name address

    {header (' http/1.1 moved Permanently ');  //prompt to issue a \

  &NBSP ; &nbsp; Header (' Location: http://www.3lian.com/ '. $request _url);  //Add a new domain name address

   }

   ?

    Add 301 redirect instructions in which file

    Adds 301 redirect instructions to the. htaccess file, using &ldquo;mod_rewrite&rdquo; technology.

    Example:

   Rewriteengine on

    Rewriterule ^ (. *) $ http://www.3lian.com /$1 [r=301,l]

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.