301 redirection code in various situations

Source: Internet
Author: User

XI sishu switched the 301 required in Seo workCodeSorted, added to favorites, and shared for reference.

 

1. Set IIS 301

Internet Information Service Manager-> virtual directory-> redirect to URL, enter the target URL to be redirected, and select "permanent resource redirection ".

2. Code redirection in ASP 301

<% @ Language = VBScript %>
<%
Response. Status = "301 moved permanently"
Response. addheader "location", "http://www.lesishu.cn/articles/301"
%>

3. 301 redirection code under ASP. NET

<SCRIPT runat = "server">
Private void page_load (Object sender, system. eventargs E)
{
Response. Status = "301 moved permanently ";
Response. addheader ("location", "http://www.lesishu.cn/articles/301/");
}
</SCRIPT>

4. php 301 redirection code

Header ("HTTP/1.1 301 moved permanently ");
Header ("Location: http://www.lesishu.cn/articles/301 ");
Exit ();

5. The 301 redirection code in cgi Perl

$ Q = new CGI;
Print $ q-> redirect ("http://www.new-url.com /");

6. 301 redirection code under JSP

<%
Response. setstatus (301 );
Response. setheader ("location", "http://www.lesishu.cn /");
Response. setheader ("connection", "close ");
%>

7. Switch to code 301 in Apache

Create a new. htaccess file and enter the following content (mod_rewrite must be enabled ):

1) switch the domain name without WWW to the domain name with WWW

Options + followsymlinks
Rewriteengine on
Rewritecond % {http_host} ^ lesishu.cn [Nc]
Rewriterule ^ (. *) $ http://www.lesishu.cn/#1 [L, r = 301]

2) redirect to a new domain name

Options + followsymlinks
Rewriteengine on
Rewriterule ^ (. *) $ http://www.lesishu.cn/#1 [L, r = 301]

3) use regular expressions for 301 redirection to achieve pseudo-static

Options + followsymlinks
Rewriteengine on
Rewriterule ^ news-(. +) \. html $ news. php? Id = $1

Add news. php? Ids0123the address is directed to news-123.html.

8. Configure 301 redirection in vhosts. conf under Apache

To achieve URL standardization, Seo usually redirects a domain name without WWW to a domain name with www. The configuration in vhosts. conf is as follows:

<Virtualhost *: 80>
Servername www.lesishu.cn
DocumentRoot/home/lesishu
</Virtualhost>

<Virtualhost *: 80>
Servername lesishu.cn
Redirectmatch permanent ^/(. *) http://www.lesishu.cn/#1
</Virtualhost>

In addition to the preceding two methods in Apache, there are other configuration methods and optional parameters. We recommend that you read the Apache documentation.

301 steering Condition Detection

    1. Http://www.seoconsultants.com/tools/headers.asp
    2. Http://www.internetofficer.com/seo-tool/redirect-check/

Author: Yan sishu
Original: dianshi interactive search engine optimization blog

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.