PHP Tutorial: How to implement the 301 redirect _php tutorial

Source: Internet
Author: User
What is 301 redirect? 301 redirect is when your website address changes, such as changing the domain name, website revision and so on, you want visitors or search engines to jump to the new address to visit the site, then you need to do 301 redirect. There are many ways to implement 301 redirection, this article mainly describes how PHP program to achieve 301 redirection.

implementing 301 redirect PHP code


$the _host = $_server[' http_host '); Tag gets the current domain name

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

if ($the _host!== ' www.bkjia.com')//No change of domain name address

{Header (' http/1.1 301 Moved permanently ');//Prompt Issued 301

Header (' Location: http://www.bkjia.com/'. $request _url); Add a new domain name address

}

?>

in which file to add 301 redirect Instructions

Added 301 redirect instructions in the. htaccess file, using "mod_rewrite" technology.

Example:

Rewriteengine on

Rewriterule ^ (. *) $ http://www.bkjia.com/$1 [R=301,l]

http://www.bkjia.com/PHPjc/371840.html www.bkjia.com true http://www.bkjia.com/PHPjc/371840.html techarticle What is 301 redirect? 301 redirect is when your website address changes, such as changing the domain name, website revision and so on, you want visitors or search engines to jump to the new address to visit ...

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