301 Jumps to the website

Source: Internet
Author: User

Previously maintained a site needs to change the domain name, so to do the domain name jump settings. Collected a bit of information found, this one thought "simple" a jump, or a little attention to the "learning".

The HTTP protocol is known to all, and the return header has a status field that is used to indicate some state of the returned information. For example, we are familiar with 200,404,500 and so on. One of the more common is the 302 redirect, the browser receives this return value, recognizes this 302 redirect State, will read the header information in the Location field contained in the redirect URL, and then access the new address.

It sounds like this 302 redirect and the domain we need to jump a bit, but here is a problem, our site is a certain weight and the like to mark the site's traffic, such as data, if we change the new domain name, this kind of information is lost, so if the simple use of 302 Redirect to achieve the jump, Then the weight of our website and so on have to re-come, this is obviously not cost-effective.

Therefore, there is a similar jump status in HTTP, 301 permanent jump, this means that the current page to a permanent jump to a new page, the weight of the original site, and so on, will directly inherit the new website up. This is the way we change the domain name, guide users to access the new domain name, maintain the weight of the site before the use of the Jump method.

Here is an example of a simple implementation in JSP 2:

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%>
<%response.setstatus (301), Response.setheader ("Location", "http://www.ahwebs.com/"); Response.setheader (" Connection "," close ");%>
<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%>  <%  Stringservername=Request.getservername (); StringServerpath=Request.getservletpath (); Stringaddres="http://www.baidu.com";  Response.setstatus (httpservletresponse.sc_moved_permanently); Response.setheader (" Location", addres); %> 

301 Jumps to the website

Related Article

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.