ASP. ASP 301 Redirect Implementation code _php tutorial

Source: Internet
Author: User
A lot of online tutorials on how to do 301 redirects, whether it's a full-site redirect or a single-page redirect. Take my www.bKjia.c0m for example, because many times you do not have a standalone server or your Apache does not support the. haccess file, and so on, you have to use the scripting language to instance 301 redirect.

A lot of online tutorials on how to do 301 redirects, whether it's a full-site redirect or a single-page redirect. Take my www.bKjia.c0m for example, because many times you do not have a standalone server or your Apache does not support the. haccess file, and so on, you have to use the scripting language to instance 301 redirect.
1.1 No WWW domain name transferred to WWW domain name
Copy the code code as follows:

Rewriteengine on
Rewritecond%{http_host} ^bkjia.c0m [NC]
Rewriterule ^ (. *) $ http://www.bkjia.c0m/$1 [R=301,NC]

1.2 Entire station 301 redirects
Copy the code code as follows:

Options +followsymlinks
Rewriteengine on
Rewritecond%{http_host} ^bkjia.c0m [NC]
Rewriterule ^ (. *) $ http://www.bkjia.c0m/$1 [l,r=301]
Rewritecond%{http_host} ^www.bkjia.c0m [NC]
Rewriterule ^ (. *) $ http://bkjia.c0m/$1 [l,r=301]

Another way to do this is in the index.php tutorial in the root directory.
Copy the code code as follows:

Header ("http/1.1 301 Moved Permanently");
Header ("location:http://bkjia.c0m/");
Exit ();

2. asp Tutorial Host 301 redirect
Add the following lines at the top of the index.asp or default.asp:
The code is as follows:
Copy the code code as follows:

<%
response.status= "301 Moved Permanently"
Response.AddHeader "Location", "www.bKjia.c0m"
Response.End
%>

3. ASP. NET Tutorial Host 301 redirect
ASP. NET:

response.status = "301 Moved Permanently";
Response.AddHeader ("Location", "http://www.bKjia.c0m");
}


I encapsulated in a class:
Copy the code code as follows:

using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Namespace Classlib
{
public class Urlclass
{
private bool flag301 = false;//whether to start 301
private bool Isindex = false;//returns to the home page or remains on the current
///
constructor function
///
/// Whether to start 301
/// Page
/// Format www.xxx.com
Public Urlclass (bool FL, page page, string strurl)
{
flag301 = FL;
url301 (page, strurl);
}
///
Back to Home
///
///
/// Format www.xxx.com
public void url301 (Page page, string strurl)
{
301 Redirects
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 Redirects
Copy the code code as follows:

Header (' http/1.1 301 Moved Permanently ');//301 head issued
Header (' location:http://www. ') $strdomain. $request _uri);//jump to my new domain address

I wrote 301 code with the 301.inc.php file, and it was all referenced on the other file headers.
Copy the code code as follows:

//-----------------------------------
301 Redirects
$strdomain = "chinawecan.com";
$the _host = $_server[' http_host '); Get access to the domain name you entered
$request _uri = isset ($_server[' Request_uri ')? $_server[' Request_uri ': ";//determine the address after the part
if ($the _host!== ' www. $strdomain)//This is my previous domain name
{
/* "!==" is not exactly equal to the meaning, can also use "! =" does not equal, so that can be the previous domain name,
including Gcxirang.com, www.gcxirang.com, and the new domain I gcidc.net all redirected to www.gcidc.net*/
Header (' http/1.1 301 Moved Permanently ');//301 head issued
Header (' location:http://www. ') $strdomain. $request _uri);//jump to my new domain address
}
//----------------------------------
?>

The references are as follows:
Copy the code code as follows:

//-----------------------------------
301 Redirects
Include (' include/301.inc.php ');
?>

301 redirects for 5 jsp tutorials
such as 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
%>

http://www.bkjia.com/PHPjc/632359.html www.bkjia.com true http://www.bkjia.com/PHPjc/632359.html techarticle a lot of online tutorials on how to do 301 redirects, whether it's a full-site redirect or a single-page redirect. Let's take my www.111cn.net as an example, because many times you don't have a standalone server or ...

  • 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.