Two perfect solutions for 301 redirection

Source: Internet
Author: User

Introduction: This is a detailed page for the perfect solution to 301 redirection. It introduces PHP, related knowledge, skills, experience, and some PHP source code.

Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 337546 'rolling = 'no'>

This article was also written on the gevin blog before gevin.ArticleThe full text is as follows:

301 redirection is really a good method. The previous article gevin also said that this blog was unfortunately changed to a domain name. Once the domain name is changed, the previous hard-working blog results will be decommissioned, the relevant links on the Internet will not be opened, and the search engine indexing will also be a cup of cake ......

Fortunately, 301 redirection can effectively solve this problem. As described in the moonlight blog,

301 redirection promotes Search Engine Optimization

From the perspective of search engine optimization, 301 redirection is the most feasible method for URL redirection. When the domain name of a website changes, the search engine only indexes the new website and transfers the original external links under the old address to the new one, in this way, the ranking of websites will not be affected by changes in the website. Similarly, when you use the 301 permanent redirection command to direct multiple domain names to the primary domain of the website, the ranking of the website will not have any negative impact.

For more information about 301 redirection, Google. This article only introduces the implementation method!

301. I have previously written an article about the implementation of redirection. However, the solution in this article is relatively simple and can only jump to the home page. The two methods described in this article are as follows, 301 redirection can be implemented perfectly.

Method 1: Modify the. htaccess File

CodeAs follows:

 
<Ifmodule mod_rewrite.c>
Rewriteengine on
Rewritecond % {http_host} blog. iflyhigher. TK $ [Nc]
Rewriterule ^ (. *) $ http://blog.igevin.info/#1 [R = 301, l]

Rewritecond % {http_host} iflyhigher. TK $ [Nc]
Rewriterule ^ (. *) $ http://igevin.info/#1 [R = 301, l]

Rewritecond % {http_host} moiya. TK $ [Nc]
Rewriterule ^ (. *) $ http://igevin.info/#1 [R = 301, l]
</Ifmodule>

This blog needs to redirect the three domain names, so it writes a lot. The key code is two sentences.

 
Rewritecond % {http_host} blog. iflyhigher. TK $ [Nc]
Rewriterule ^ (. *) $ http://blog.igevin.info/#1 [R = 301, l]

The red domain name is the old domain name to be redirected, and the green domain name is the current website domain name.

Method 2: Use PHP redirection code

Create an index. php file, and then follow the code below to make simple modifications according to your own redirection requirements:

<? PHP
$ The_host = $ _ server ['HTTP _ host'];
$ Request_uri = isset ($ _ server ['request _ URI '])? $ _ Server ['request _ URI ']: '';

Switch ($ the_host)
{
Case "www. iflyhigher. TK ":
Case "iflyhigher. TK ":
$ Location = "Location: http://igevin.info". $ request_uri;
Break;
Case "blog. iflyhigher. TK ":
$ Location = "Location: http://blog.igevin.info". $ request_uri;
Break;
Case "www. moiya. TK ":
Case "moiya. TK ":
$ Location = "Location: http://igevin.info ";
Break;
Default:
$ Location = "Location: http://igevin.info ";
Break;
}

Header ('HTTP/1.1 301 moved permanently ');
Header ($ location );

Exit ();
?>

If you only need to redirect a domain name, you can simplify the code into the following form:

<? PHP
$ The_host = $ _ server ['HTTP _ host']; // obtain the entered Domain Name
$ Request_uri = isset ($ _ server ['request _ URI '])? $ _ Server ['request _ URI ']: ''; // you can specify the request
If ($ the_host! = 'Igevin. info') // igevin.info is my current domain name
{
Header ('HTTP/1.1 301 moved permanently '); // issue the 301 Header
Header ('location: http://igevin.info '. $ request_uri); // jump to my new domain address
Exit ();
}
?>

Note that the last exit () function must be written. I didn't write it at first, and the result can only be redirected to the home page, such as http://blog.iflyhigher.tk/guestbook.

Finally, some details about redirection

As we need to redirect the three domain names, before redirection, I first bind these three domain names to my server as addon domain and direct these three domain names to the same folder, in this way, you only need to modify. htaccess file or index. PHP file. If there is no. htaccess file or index. php file, create a new one.

I hope this article will help anyone who needs 301 redirection.

Reprinted to indicate the source:Gevin blog,Article:Two perfect solutions for 301 redirection

Love J2EE follow Java Michael Jackson video station JSON online tools

Http://biancheng.dnbcw.info/php/337546.html pageno: 9.

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.