1.1 Transfer without www domain name to www domain name
Copy the code as follows:
Rewriteengine on
Rewritecond % {http_host} ^ 111cn.net [nc]
Rewriterule ^ (. *) $ http://www.111cn.net/#1 [r = 301, nc]
1.2 whole site 301 redirection
Copy the code as follows:
Options + followsymlinks
Rewriteengine on
Rewritecond % {http_host} ^ 111cn.net [nc]
Rewriterule ^ (. *) $ http://www.111cn.net/#1 [l, r = 301]
Rewritecond % {http_host} ^ www.111cn.net [nc]
Rewriterule ^ (. *) $ http://111cn.net/#1 [l, r = 301]
In the index. php tutorial under the root directory
Copy the code as follows:
Header ("http/1.1 301 moved permanently ");
Header ("location: http://111cn.net /");
Exit ();
2. asp tutorial host 301 redirection
Add the following lines to the top of index. asp or default. asp:
The code is as follows:
Copy the code as follows:
<%
Response. status = "301 moved permanently"
Response. addheader "location", "www.111cn.net"
Response. end
%>
3. asp.net tutorial host 301 redirection
Asp. net:
Response. status = "301 moved permanently ";
Response. addheader ("location", "http://www.111cn.net ");
}
I encapsulate it in a class:
Copy the code as follows:
Using system;
Using system. collections. generic;
Using system. text;
Using system. web. ui;
Using system.web.ui.html controls;
Namespace classlib
{
Public class urlclass
{
Private bool flag301 = false; // whether to start 301
Private bool isindex = false; // whether to return to the home page or retain it on the current page
/// <Summary>
/// Constructor
/// </Summary>
/// <Param name = "fl"> enable 301 </param>
/// <Param name = "page"> page </param>
/// <Param name = "strurl"> format: www.xxx.com </param>
Public urlclass (bool fl, page, string strurl)
{
Flag301 = fl;
Url301 (page, strurl );
}
/// <Summary>
/// Return to the home page
/// </Summary>
/// <Param name = "page"> </param>
/// <Param name = "strurl"> format: www.xxx.com </param>
Public void url301 (page, string strurl)
{
// Redirect 301
If (page. request. url. dnssafehost! = Strurl & flag301 = true)
{
Page. response. clear ();
Page. response. statuscode = 301;
Page. response. status = "301 movedpermanently ";
Page. response. addheader ("location", "http: //" + strurl );
Page. response. end ();
}
}
}
}
4. php 301 redirection
Copy the code as follows:
Header ('http/1.1 301 moved permanently '); // issue the 301 header
Header ('Location: http: // www. '. $ strdomain. $ request_uri); // jump to my new domain name address
I used the 301. inc. Php file to write the 301 code, which can be referenced in other file headers.
Copy the code as follows:
<? Php
//-----------------------------------
// Redirect 301
$ Strdomain = "chinawecan.com ";
$ The_host = $ _ server ['http _ host']; // Obtain the entered domain name
$ Request_uri = isset ($ _ server ['request _ uri '])? $ _ Server ['request _ uri ']: ''; // judge the part after the address
If ($ the_host! = 'Www. '. $ strdomain) // This is my previous domain name
{
/* "! = "Is not completely equal to the meaning, you can also use"! = "Not equal to, in this way, you can replace the previous domain name,
Including gcxirang.com, www.gcxirang.com, and all my gcidc.net in the new domain name are redirected to www.gcidc.net */
Header ('http/1.1 301 moved permanently '); // issue the 301 header
Header ('Location: http: // www. '. $ strdomain. $ request_uri); // jump to my new domain name address
}
//----------------------------------
?>
Reference:
Copy the code as follows:
<? Php
//-----------------------------------
// Redirect 301
Include ('include/301. inc. Php ');
?>
5. 301 redirection in jsp tutorial
For example, the page article. jsp
[Code]
<% @ Page language = "java" contenttype = "text/html; charset = utf-8" pageencoding = "UTF-8" %>
<%
Response. setstatus (https tutorial ervletresponse. SC _moved_permanently );
Response. setheader ("location", "/other. jsp ");
Return;
%>