Complete Set of Jump code in various languages and servers 301

Source: Internet
Author: User

Complete Set of Jump code in various languages and servers 301

This article mainly introduces a variety of languages, server 301 jump code complete set, this article explains the IIS 301 settings, ASP 301 redirection code, ASP. net, PHP, CGI, Perl, and JSP. For more information, see

301 redirection is usually used for changing the domain name of a website and for maintaining uniformity of links. For example, your original domain name www.a.com is now changed to www. B .com. After you use the 301 jump, the access to www.a.com/about.htmlwill automatically become www. B .com/about.html. Next, let's take a look at the code for setting up 301 for beginners:

301 complete jump code (ASP | PHP | JSP |. NET)

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

The Code is as follows:

<% @ Language = VBScript %>

<%

Response. Status = "301 Moved Permanently"

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

%>

3. 301 redirection code under ASP. Net

The Code is as follows:

  

4. PHP 301 redirection code

The Code is as follows:

Header ("HTTP/1.1 301 Moved Permanently ");

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

Exit ();

5. The 301 redirection code in CGI Perl

The Code is as follows:

$ Q = new CGI;

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

6. 301 redirection code under JSP

The Code is as follows:

<%

Response. setStatus (301 );

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

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

%>

7. 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:

The Code is as follows:

  

ServerName www.jb51.net

DocumentRoot

  

  

ServerName jb51.net

RedirectMatch permanent ^/(. *) http://www.jb51.net/#1

  

8. 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

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 a new domain name

The Code is as follows:

Options + FollowSymLinks

RewriteEngine on

RewriteRule ^ (. *) $ http://www.jb51.net/#1 [L, R = 301]

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

The Code is as follows:

Options + FollowSymLinks

RewriteEngine on

RewriteRule ^ news-(. +) \. html $ news. php? Id = $1

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

Finally, when you use the 301 permanent redirection command to direct multiple domain names to the primary domain name of the website, it does not have any negative impact on the ranking of the website. Hope to 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.