What is 301 redirection? How to perform 301 redirection?

Source: Internet
Author: User

301 redirection and 301 redirection are the same meanings.

What is 301 redirection?

How to perform 301 redirect

Redirection implementation in various environmentsCode

IIS redirection

 

ColdFusion redirection

<. Cfheader statuscode = "301" statustext = "moved permanently">
<. Cfheader name = "location" value = "http://www.new-url.com">

PHP redirection

<?
Header ("HTTP/1.1 301 moved permanently ");
Header ("Location: http://www.new-url.com ");
?>

ASP redirection

<% @ Language = VBScript %>
<%
Response. Status = "301 moved permanently"
Response. addheader "location", "http://www.new-url.com /"
%>

ASP. NET redirection

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

JSP (Java) redirection

<%
Response. setstatus (301 );
Response. setheader ("location", "http://www.new-url.com /");
Response. setheader ("connection", "close ");
%>

Cgi Perl redirection

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

Ruby on Rails redirection

Def old_action
Headers ["status"] = "301 moved permanently"
Redirect_to "http://www.new-url.com /"
End

Old domain redirection to new domain (htaccess redirection)

Use the following code to create a. htaccess file. This will ensure that all directories and webpages in your old domain will be correctly redirected to the new domain name..The htaccess file must be placed in the root directory of your old website.

Options + followsymlinks
Rewriteengine on
Rewriterule (. *) http://www.newdomain.com/#1 [R = 301, l]

Replace www.newdomain.com with your actual domain name.

In addition to redirection, we recommend that you notify the partner to modify the link and re-link it to your new website.

Note: This method is valid only when Apache is used on the Linux server and Apache Mod-rewrite is enabled.

 

Redirect to www (htaccess redirect)

Use the following code to create a. htaccess file. This ensures that all requests are redirected from domain.com to www.domain.com again.
Options + followsymlinks
Rewriteengine on
Rewritecond % {http_host} ^ domain.com [Nc]
Rewriterule ^ (. *) $ http://www.domain.com/#1 [R = 301, NC]

Replace www.newdomain.com with your actual domain name.

Note: This method is valid only when Apache is used on the Linux server and Apache Mod-rewrite is enabled.

 

 

Redirection detection tool

Http://www.webconfs.com/redirect-check.php

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.