All languages, server 301 Jump Code Complete

Source: Internet
Author: User
Tags iis

This article mainly introduced a variety of languages, server 301 Jump Code Complete, this article explained the IIS under 301 Settings, ASP 301 to the code, ASP. NET 301 to the code, PHP 301 to the code, CGI perl 301 to the code, JSP under the 301 steering Code, etc., the need for friends can refer to the following

301 jump is usually used in the site to change the domain name and to maintain the unity of the links used. For example, your original domain name www.a.com now replaced www.b.com, with 301 jump, Access www.a.com/about.html will automatically become www.b.com/about.html. Let's take a look at the code set 301 to facilitate the novice:

301 Jump Code Complete (asp| php| jsp|. NET)

1, IIS under 301 settings

Internet Information Services Manager-> virtual directory-> redirect to URL, enter the destination URL that needs to be redirected, and select Permanent redirect for resources

2, ASP under the 301 steering code

The code is as follows:

<%@ Language=vbscript%>

<%

Response.status= "Moved Permanently"

Response.AddHeader "Location", "http://www.jb51.net/"

%>

3, ASP. NET 301 Steering Code

The code is as follows:

  

4, PHP under the 301 steering code

The code is as follows:

Header ("http/1.1 moved Permanently");

Header ("location:http://www.jb51.net/");

Exit ();

5, CGI Perl under the 301 steering code

The code is as follows:

$q = new CGI;

Print $q->redirect ("http://www.jb51.net/");

6, JSP under the 301 steering code

The code is as follows:

<%

Response.setstatus (301);

Response.setheader ("Location", "http://www.jb51.net/");

Response.setheader ("Connection", "close");

%>

7, Apache under the vhosts.conf configuration 301 Turn

In order to achieve URL normalization, SEO will usually change the domain name without www to the WWW domain name, vhosts.conf is configured as:

The code is as follows:

  

ServerName www.jb51.net

DocumentRoot

  

  

ServerName jb51.net

Redirectmatch permanent ^/(. *) http://www.jb51.net/$1

  

8, Apache under 301 turn Code

Create a new. htaccess file and enter the following (you need to turn on mod_rewrite):

1 Change the domain name without www to the domain name with www

The code is as follows:

Options +followsymlinks

Rewriteengine on

Rewritecond%{http_host} ^jb51.net [NC]

Rewriterule ^ (. *) $ http://www.jb51.net/$1 [l,r=301]

2 Redirect to new domain

The code is as follows:

Options +followsymlinks

Rewriteengine on

Rewriterule ^ (. *) $ http://www.jb51.net/$1 [l,r=301]

3) using regular 301 steering to achieve pseudo static

The code is as follows:

Options +followsymlinks

Rewriteengine on

Rewriterule ^news-(. +). html$ news.php?id=$1

Turn news.php?id=123 Such an address to news-123.html

Finally: When using the 301 Permanent redirect command to have multiple domain names point to the site's main domain name, it will not have any negative impact on the ranking of the site. I hope it will help you.

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.