PHP Site 301 Orientation Method Detailed

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

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:

PHP code
? Header ("http/1.1 moved Permanently");
Header ("Location:http://www.gcidc.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)

<?php


$the _host = $_server[' http_host '];//get into the domain name entered


$request _uri = isset ($_server[' Request_uri '))? $_server[' Request_uri ']: '//To determine the back part of the address


if ($the _host!== ' www.gcidc.net ')//This is my previous domain address


{


header (' http/1.1 moved Permanently ');/Send 301 head


header (' location:http://www.gcidc.net '. $request _uri);//jump to my new domain address


}


?>

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

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

<?php include ("301.inc.php"); 301 redirect?>

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.

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.