301 redirection code under ASP, Asp.net, PHP, and JSP, and whole site redirection

Source: Internet
Author: User

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.

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.