PHP code for 301 redirection _ PHP Tutorial

Source: Internet
Author: User
PHP code for 301 redirection. PHP code for 301 redirection PHP code for 301 redirection: header (HTTP1.1301MovedPermanently); code for sending a 301 header (Location: www... $ strDomain. $ request PHP code for 301 redirection

The code for PHP to implement 301 redirection is as follows:

Header ('http/1.1 301 Moved Permanently '); // issue the 301 header

Header ('Location: http: // www. '. $ strDomain. $ request_uri); // jump to my new domain name address

I used the 301. inc. php file to write the 301 code, which can be referenced in other file headers.

  

//-----------------------------------

// Redirect 301

$ StrDomain = "chinawecan.com ";

$ The_host = $ _ SERVER ['http _ host']; // Obtain the entered domain name

$ Request_uri = isset ($ _ SERVER ['request _ URI '])? $ _ SERVER ['request _ URI ']: ''; // judge the part after the address

If ($ the_host! = 'Www. '. $ strDomain) // This is my previous domain name

{

/* "! = "Is not completely equal to the meaning, you can also use"! = "Not equal to, in this way, you can replace the previous domain name,

Including gcxirang.com, www.gcxirang.com, and all my gcidc.net in the new domain name are redirected to www.gcidc.net */

Header ('http/1.1 301 Moved Permanently '); // issue the 301 header

Header ('Location: http: // www. '. $ strDomain. $ request_uri); // jump to my new domain name address

}

//----------------------------------

?>

Reference:

  

//-----------------------------------

// Redirect 301

Include ('include/301. inc. php ');

?>

The code for PHP to implement 301 redirection is as follows: header ('http/1.1 301 Moved Permanently '); // send the 301 header ('Location: HTTP: // www. '. $ strDomain. $ request...

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.