asp.net php asp JSP 301 redirect Code (set) _ Other synthesis

Source: Internet
Author: User
Tags php file to domain
1, Linux host redirect
GoDaddy Liunx host, GoDaddy itself has supported Apache, So you can create a. htaccess file directly, in general, you can't create it locally. htaccess can create a txt format file, and then rename it to ". htaccess" when uploaded to the root directory. A lot of tutorials on how to do 301 redirects on the web, whether it's a whole-station redirect or a single page redirect. Here's my www.jb51.net, for example.
1.1 No WWW domain name transfer to WWW domain name
Copy Code code as follows:

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

1.2 Whole Station 301 redirect
Copy Code code as follows:

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

The other is index.php in the root directory.
Copy Code code as follows:

Header ("http/1.1 moved Permanently");
Header ("location:http://jb51.net/");
Exit ();

2, ASP host 301 redirect
Add the following lines to the top of the index.asp or default.asp:
The code is as follows:
Copy Code code as follows:

<%
Response.status= "Moved Permanently"
Response.AddHeader "Location", "Http://www.jb51.net"
Response.End
%>

3, asp.net host 301 redirect
ASP. NET:
Response.Status = "Moved Permanently";
Response.AddHeader ("Location", "http://www.jb51.net");
}
I am encapsulated in a class:
Copy 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;//whether to return to the home page or remain on the current page
<summary>
Constructors
</summary>
<param name= "FL" > whether to start 301</param>
<param name= "page" >Page</param>
<param name= "strURL" > Format www.xxx.com</param>
Public Urlclass (bool FL, page page, string strurl)
{
flag301 = FL;
URL301 (page, strurl);
}
<summary>
Back to Home
</summary>
<param name= "page" ></param>
<param name= "strURL" > Format www.xxx.com</param>
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 = "movedpermanently";
Page. Response.AddHeader ("Location", "http://" + strurl);
Page. Response.End ();
}
}
}
}

4 PHP's 301 redirects
Copy Code code as follows:

Header (' http/1.1 moved Permanently ');/Send 301 Head
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's all on the head of the other file.
Copy Code code as follows:

<?php
//-----------------------------------
301 redirect
$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 ']: "//To determine the back part of the address
if ($the _host!== ' www. ') $strDomain)//This is my previous domain name.
{
/* "!==" is not exactly equal to the meaning, can also use "!=" is not equal to, so that you can put the previous domain name,
including Gcxirang.com, www.gcxirang.com, and the new domain name I gcidc.net all redirected to www.gcidc.net*/
Header (' http/1.1 moved Permanently ');/Send 301 Head
Header (' location:http://www. ') $strDomain. $request _uri);//jump to my new domain address
}
//----------------------------------
?>

The reference is as follows:
Copy Code code as follows:

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

5 JSP's 301 redirect
such as page article.jsp
[Code]
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%>
<%
Response.setstatus (httpservletresponse.sc_moved_permanently);
Response.setheader ("Location", "/other.jsp");
Return
%>
[Code]


How do you achieve the 301 turn in Apache?
The method of editing. htaccess.
Note: Be sure to back up the. htaccess file in the corresponding directory before you set 301 redirection.
1. redirect domain.com to www.domain.com
This redirect is designed to make the domain name unique, is the website SEO must do, the back redirects www.domain.com to domain.com is also for the same reason, but the form is different.
Open the. htaccess file and add the following rules. (The following rule is for the primary domain name, and the subdomain is to be modified)
Rewriteengine on
Rewritecond%{http_host}!^www.domain.com$ [NC]
Rewriterule ^ (. *) $ http://www.domain.com/$1 [l,r=301]

2. redirect www.domain.com to domain.com
Rewriteengine on
Rewritecond%{http_host}!^domain.com$ [NC]
Rewriterule ^ (. *) $ http://domain.com/$1 [l,r=301]

3. REDIRECT olddomain.com to www.newdomain.com
Rewriteengine on
Rewritecond%{http_host}!olddomain.com$ [NC]
Rewriterule ^ (. *) $ http://www.newdomain.com/$1 [l,r=301]

4. redirect olddomain.com to newdomain.com
Rewriteengine on
Rewritebase/
Rewritecond%{http_host}!olddomain.com$ [NC]
Rewriterule ^ (. *) $ http://newdomain.com/$1 [l,r=301]

5. redirect domain.com/file/file.php to otherdomain.com/otherfile/other.php
Rewritecond%{http_host} ^www.domain.com$
Rewriterule ^file/file.php$ http://www.otherdomain.com/otherfile/other.php [r=301,l]
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.