301 redirect Code and methods

Source: Internet
Author: User
Tags servervariables

301 redirect Code and methods

301 Redirects under PHP

  

Header ("http/1.1 moved Permanently");

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

?

301 redirects under ASP

<%@ Language=vbscript%>

<%

Response.status= "Moved Permanently"

Response.AddHeader "Location", "Http://www.111cn.net"

%>

Asp. NET, 301 redirects


301 redirects under the ColdFusion

<.cfheader statuscode= "statustext=" "Moved Permanently" >

<.cfheader name= "Location" value= "Http://www.111cn.net" >

Old domain name redirected to new domain

Create a. htaccess file and write the code provided below to the file to ensure that all directories or pages of the old domain name are correctly jumped to the new domain.

Remember that. htaccess files must be placed in the root directory of the old site, and the new site will keep the same directory structure and Web files as the old site

Options +followsymlinks

Rewriteengine on

Rewriterule (. *) http://www.111cn.net/[r=301,l]

Please change the above www.111cn.net to the domain name you want to jump to.

In addition, I suggest you belongs the old site's external links, and contact the corresponding site to modify the import chain URL to point to the new site.


4. The use of "mod_rewrite" technology

Changes made through this technology will be reflected in the. htaccess file, in the form of:

Options +followsymlinks

Rewriteengine on

Rewritecond% ^cfan365.cn

Rewriterule ^ (. *) $ http://www.111cn.net/[r=permanent,l]

5. Binding/local DNS (domain alias jump)

If you have permission to edit the local DNS records, you can resolve the problem by simply adding a record.

If you do not have this permission, you can require the Web site hosting service to set up the DNS server accordingly.

Settings for the DNS server

To point aaa.cfan365.cn to www.111cn.net, you need to add an alias record to the DNS service, written as: AAA in CNAME www.111cn.net.

If you need to configure a large number of virtual domain names, you can write: * in CNAME www.111cn.net.

This redirects all cfan365.cn records that have not been set to the end of the www.111cn.net.

6. Implement 301 redirects with asp/php:

The code has been described above.

Comments and suggestions from senior SEO expert dan Thies

Dan Thies had a deep understanding of business.com's problems because he had a similar experience. His website has a member tracking script, where a member's site is mapped to this tracking script through 302 commands, and this tracking script is mapped to his homepage via 302. When Google used "keyword research" to search, his home page ranked in the top ten, but the address shows that the member's Web site. The results make him laugh and cry: The visitor enters his website through Google search results, but he has to pay for the amount of the visit to that member! Later, he used robots.txt file to prohibit spiders tracking access to his member tracking script to solve the problem.

For Business.com,dan Thies, "There are still some problems with Google's 302 redirect", but that does not mean that Google does not allow 302 redirects. Business.com have not been blocked or punished, they simply returned the wrong response. ”

Dan Thies recommends that if you use a tracking url/script and you have to redirect the visitor to a landing page, you must prohibit spiders from accessing the second redirect in the robots.txt file. If you do not redirect the tracking url/script, but simply copy the contents of the other URL, you should prevent the spiders from accessing the trace URL in the robots.txt file in case the search engine is penalized for duplication of content.

301 on the experience of redirect

A multi-domain site Master's experience:

"I have only one site, the main domain name is www.111cn.net, in addition to such as Domain1.com, domain2.com, domain3.com and so on a total of more than 10 domain names." All of these subordinate domain names are mapped to www.111cn.net, and all domain names correspond to the same IP address. Because in fact I only have one site, one site can only correspond to a. htaccess file, it is obviously impossible to directly modify the. htaccess file to achieve redirection. I used the following steps:

A. Separate the domain1.com from the cfan365.cn and make it an ordinary independent web site on the server.

B. Create a. htaccess text file for domain1.com and set the redirection code in the file to:

Redirect permanent/http://www.111cn.net/

The modified. htaccess file is then passed to the domain1.com server.

This step can also be done in the Domain name Control Panel.

Directory ABC under the first level domain name Www.111cn.net
The original access address is: WWW.111CN.NET/ABC
Now you want to add a level two domain name to catalog ABC Abc.111cn.net
How to permanently redirect the Www.111cn.net/abc abc.111cn.net
Server environment: win2003+iis6+php

WWW.XXX.NET/ABC is no longer a domain name, browser access to the end of a page is the request, redirect can only be determined by the www.xxx.net above ABC files.

Another problem is that after 301 permanent orientation,
How do I pass the get parameter of a dynamic page?
Permanently directs abc/index.php to abc.xxx.com/index.php
If you type in the Address bar
Abc/index.php?xxx=123
The page will go directly to the
abc.xxx.com/index.php
But get parameter xxx=123 is gone.
Is it necessary to add code to the head in a dynamic file:
First judge the URL of the client, if not abc.xxx.com/index.php
On the output
Header ("http/1.1 moved Permanently");
Header ("location:abc.xxx.com/index.php?") Get parameter and value ");


The implementation of PHP under the Way (reference):

The. htaccess file code is as follows (bloghuman.com. htaccess so set):

Options +followsymlinks

Rewriteengine on

Rewritecond%{http_host} ^bloghuman.com [NC]

Rewriterule ^ (. *) $ HTTP://WWW.BLOGHUMAN.COM/$1[R=301,NC]

Note 1: If the user accesses the http://bloghuman.com/, jumps to the http://www.bloghuman.com and returns a 301 status code; When the user accesses the http://bloghuman.com/post/301.htm, Jumps to http://www.bloghuman.com/post/301.htm and returns a 301 status code.

NOTE 2: Test url:http://www.wlxs.com.cn/, you can access http://www.wlxs.com.cn/post/301.htm

I configured the. htaccess file under wlxs.com.cn to make it 301 jump to Http://www.bloghuman.com/post/301.htm

My. htaccess configuration is implemented by the primary domain name (bloghuman.com) 301 to jump to level two domain name (www.bloghuman.com);

Conclusion:

Options +followsymlinks

Rewriteengine on

Rewritecond%{http_host} ^111cn.net [NC]

Rewriterule ^ (. *) $ HTTP://WWW.111CN.NET/$1[R=301,NC]

ASP script implementation of the 301 Jump method:

<%

If request. ServerVariables ("http_host") = "domain1.com" or request. ServerVariables ("http_host") = "111cn.net" Then

If Request.ServerVariables ("Query_string") <> "" Then p= "?"

Response.status= "Moved Permanently"

Response.AddHeader "Location", "Http://www.111cn.net" &request.servervariables ("Script_name") &p& Request.ServerVariables ("Query_string")

Response.End

End If

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.