PHP Implementation 301 Permanent Redirection Method _php Tutorial

Source: Internet
Author: User
This article to introduce the PHP implementation of 301 permanent redirection will not take the WWW domain name to the domain name with WWW, the implementation method is obtained.

When your site domain name changes or Web address changes (changes in the directory or the name of the Web page change), how to ensure that the site during the transition period from the search engine traffic will not be lost, and can update the search engine results in the page address? 301 redirects are an ideal way to solve this problem by directing users and search engines to the right page

The code is as follows Copy Code

$the _host = $_server[' http_host '];//get into the domain name entered
$request _url = isset ($_server[' Request_uri ') "$_server[' Request_uri ']:";//Determine the back part of the address
if ($the _host!== ' www.bKjia.c0m ')//This is where I want the previous domain address
{Header (' http/1.1 301 Moved permanently ');//301 head issued
Header (' location:http://www.bkjia.c0m '. $request _url);//jump to my new domain address
}
?>

1. Add 301 redirect instructions in the. htaccess file

Using the "mod_rewrite" technique, the shape is as follows:

The code is as follows Copy Code

Rewriteengine on
Rewriterule ^ (. *) $ http://www.bkjia.c0m/$1 [r=301,l]

http://www.bkjia.com/PHPjc/629013.html www.bkjia.com true http://www.bkjia.com/PHPjc/629013.html techarticle This article to introduce the PHP implementation of 301 permanent redirection will not take the WWW domain name to the domain name with WWW, the implementation method is obtained. When your site domain name changes or the Web address changes (Web page ...

  • 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.