PHP site to modify the code to do 301 redirect

Source: Internet
Author: User
Tags header modify php website domain root directory





About the benefits of 301 Redirect, and the General 301 Redirect method, there are many online, I do not repeat, today to say, is the PHP Web site by modifying the form of PHP Web page to do a good job of 301 redirect.






Some time ago, the author of the site to change the domain name , in doing 301 redirect, search the Internet a lot of posts, found that a lot of various methods are listed, but there is no specific how to operate, such as PHP site, is to write the following piece of code:




1

2

3

4

<?

Header ("http/1.1 moved Permanently");

Header ("Location:http://www.shuxiong.net");

? >



This code only adapts to the site migration situation, that is, the old station and the new station domain name is different, the root directory is not the same situation. If the site belongs to a website bound 2 domain names, 2 domain names of the root directory for the same, then, it will line into a dead loop. In this, the author will php site 301 Redirect Method completely release, hope to help new, if there are deficiencies, also please master pointed out, greatly appreciated.






This code is only adapted to the homepage of the 301 redirect, if the site has been included, or a large number of non-homepage outside the chain, to all directed over, there is nothing to do. The more appropriate method is to use the. htaccess to orient, simple and quick, but I do not understand this, in this, the author will be the PHP site 301 Redirect Method completely released, hope to help new people, if there are deficiencies, also please master pointed out, greatly appreciated.






First, establish a 301.inc.php (filename)





           

< ?

Header( "HTTP/1.1 301 Moved Permanently" );

Header( "Location: http://www.shuxiong.net" );

?>


           



This code is only suitable for the case of website migration, that is, the old station and the new station have different domain names and the root directory is different. If the website belongs to a website with 2 domain names and the root directory of the 2 domain names is the same, then it will be an infinite loop. Here, the author will completely release the PHP website 301 redirect method, hoping to help new people, if there are deficiencies, please also point out the experts, I am grateful.



This code is only suitable for the 301 redirect on the homepage of the website. If the website has been included, or there are a large number of non-homepage links, it is impossible to do it. More suitable method is to use .htaccess to direct, simple and fast, but I do not understand this, here, the author will completely release the PHP website 301 redirect method, hoping to help new people, if there are deficiencies, please also point out ,Greatful.



First, create a 301.inc.php (file name self-fetch)            


           

___FCKpd___3


           



The "!==" in if($the_host !== 'www.shuxiong.net') is not exactly equal, or you can use "!=" to not equal, so you can use the previous domain name, including Higotv.com, www.higotv.com and my new domain name shuxiong.net are all redirected to www.shuxiong.net.



Second, call 301.inc.php in the web page file





           

___FCKpd___4


           


           

___FCKpd___5


           



Put this code at the top of all your pages.



Ok, the redirect is done, upload the 301 file to the website directory, and you can watch your results.



Finally, provide a URL, the 301 method is more full http://www.piaoyi.org/seo/HTTP-Header-301-Moved-Permanently.html, but also thanks to the SEO staff of SEO half-acre field A lot of technical help is really a good person.



SERVER['REQUEST_URI'] : '';

/ / Determine the part after the address

If($the_host !== 'www.shuxiong.net')//This is the domain address I want to be before

{

Header('HTTP/1.1 301 Moved Permanently');// Issue 301 header

Header('Location: http://www.shuxiong.net'.$request_uri);

//Go to my new domain address

}

?>






Where the "!==" in the IF ($the _host!== ' www.shuxiong.net ') is not exactly equal to, or "!=" is not equal, this allows the previous domain name, including higotv.com, Www.higotv.com and the new domain name I shuxiong.net all redirected to Www.shuxiong.net.






Second, in the Web page file call 301.inc.php




___fckpd___4

___fckpd___5



Put this code in front of all your pages.






OK, redirect is done, 301 files uploaded to the site directory, you can go to see your results.






Finally, provide a URL, inside the 301 method comparison Total http://www.piaoyi.org/seo/HTTP-Header-301-Moved-Permanently.html, Also want to thank under SEO half mu tian seo handyman to give a lot of technical help, really a good person.







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.