asp.net php jsp asp 301 redirect implementation code_PHP tutorial

WBOY
Release: 2016-07-13 10:54:07
Original
898 people have browsed it

There are many tutorials on how to perform 301 redirection on the Internet, whether it is an entire site redirection or a single page redirection. Let's take my www.bKjia.c0m as an example. Because many times you don't have a separate server or your apache does not support .haccess files, etc., you have to use scripting language to implement 301 redirection.

There are many tutorials on how to perform 301 redirection on the Internet, whether it is an entire site redirection or a single page redirection. Let's take my www.bKjia.c0m as an example. Because many times you don't have a separate server or your apache does not support .haccess files, etc., you have to use scripting language to implement 301 redirection.
1.1 Transfer no www domain name to www domain name
Copy the code. The code is as follows:

rewriteengine on
rewritecond %{http_host} ^bKjia.c0m [nc]
rewriterule ^(.*)$ http://www.bKjia.c0m/$1 [r=301,nc]

1.2 Whole-site 301 redirection
Copy the code. The code is 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]

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

header(“http/1.1 301 moved permanently”);
header(“location:http://bKjia.c0m/”);
exit();

2. ASP tutorial host 301 redirection
Add the following lines at the very top of index.asp or default.asp:
The code is as follows:
Copy the code. The code is as follows:

<%
response.status=”301 moved permanently”
response.addheader “location”,”www.bKjia.c0m”
response.end
%>

3. asp.net tutorial host 301 redirection
asp .net:

response.status = “301 moved permanently”;
response.addheader("location","http://www.bKjia.c0m");
}


I encapsulate it in a class:
Copy the code. The code is 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;//Whether to return to the homepage or stay on the current page
///
/// Constructor
///

/// Whether to start 301
/// page
/// Format www.xxx.com
public urlclass(bool fl, page page, string strurl)
{
flag301 = fl;
url301(page, strurl);
}
///
/// Return to homepage
///

///
/// Format www.xxx.com
public void url301(page page, string strurl)
{
//301 redirect
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();
}
}
}
}

301 redirect for 4 php
Copy the code. The code is as follows:

header('http/1.1 301 moved permanently');//Send 301 header
header('location: http://www.'.$strdomain.$request_uri);//Jump to my new domain name address

I wrote the 301 code using the 301.inc.php file and quoted it in the headers of other files
Copy the code. The code is as follows:

//----------------------------------
//301 Redirect
$strdomain="chinawecan.com";
$the_host = $_server['http_host']; //Get the entered domain name
$request_uri = isset($_server['request_uri']) ? $_server['request_uri'] : '';//Determine the last part of the address
if($the_host !== 'www.'.$strdomain) //This is the previous domain name I want
{
/* "!==" means not exactly equal, you can also use "!=" not equal, in this way, you can replace the previous domain name,
Including gcxirang.com, www.gcxirang.com and my new domain name gcidc.net are all redirected to www.gcidc.net*/
header('http/1.1 301 moved permanently');//Send 301 header
header('location: http://www.'.$strdomain.$request_uri);//Jump to my new domain name address
}
//----------------------------------
?>

Quote as follows:
Copy the code. The code is as follows:

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

301 redirection of 5 jsp tutorials
Ruyi 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;
%>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632359.htmlTechArticleThere are many tutorials on how to perform 301 redirection on the Internet, whether it is an entire site redirection or a single page redirection. Let’s take my www.111cn.net as an example, because many times you don’t have a separate server or...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!