301 redirection code under ASP, Asp.net, PHP, and JSP
Use the. htaccess file for 301 redirection.
If the space does not support. htaccess files, we can use PHP/ASP code to perform 301 redirection.
In order to update the record of the search engine to the current domain name, we have made several 301 redirection tasks to share with you.
ASP 301 redirection code
Add the following lines to the top of index. asp or default. asp:
<%
Response. Status = "301 moved permanently"
Response. addheader "location", "http://blog.csdn.net/huwei2003"
Response. End
%>
PHP 301 redirection code
Add the following lines to the top of index. php:
<? PHP
Header ("HTTP/1.1 301 moved permanently ");
Header ("Location: http://blog.csdn.net/huwei2003 ");
Exit ();
?>
Asp.net 301 redirection code
<% @ Page Language = "C #" %>
<SCRIPT runat = "server">
Protected void page_load (Object sender, eventargs E)
{
HTTP context. Current. response. statuscode = 301;
Httpcontext. Current. response. Status = "301 moved permanently ";
Httpcontext. Current. response. addheader ("location", http://blog.csdn.net/huwei2003 );
}
</SCRIPT>
301 stands for permanent transfer (permanently moved). 301 redirection is the best method for search engine friendliness after a webpage address is changed. Only
If it is not for temporary migration, we recommend that you use 301 for address conversion.
301 redirection under JSP
<% @ Page Language = "Java" pageencoding = "GBK" %>
<%
Response. setstatus (response. SC _moved_permanently );
Response. addheader ("location", http://blog.csdn.net/huwei2003 );
%>
You can use filter to control the path or page to be redirected.
------------------
Set full-site redirection for IIS
In the IIS Site properties, find the main directory item with a redirect Address Setting and set the address you want to redirect.