301 Redirect Code collection (Iis,asp,php,asp.net,apache) _ Related Tips

Source: Internet
Author: User

1, IIS under 301 settings

Internet Information Services Manager-> virtual directory-> to a URL, enter the destination URL that needs to be redirected, and select Permanent redirect for resources.

In IIS, you can also implement features such as Mod_rewrite in Apache by installing the ISAPI Rewrite component, as described in the ISAPI Rewrite 3 download and the common 301 rules.

2, ASP under the 301 redirect Code

<%@ Language=vbscript%>
<%
Response.status= "Moved Permanently"
Response.AddHeader "Location", "106/"
%>

3, ASP. NET 301 REDIRECT Code

<script runat= "Server" >
private void Page_Load (object sender, System.EventArgs e)
{
Response.Status = "Moved Permanently";
Response.AddHeader ("Location", "106/");
}
</script>

4, PHP under the 301 redirect Code

Header ("http/1.1 moved Permanently");
Header ("location:106/");
Exit ();

5.301 redirect Code under CGI Perl

$q = new CGI;
Print $q->redirect ("");

6, JSP under the 301 redirect Code

<%
Response.setstatus (301);
Response.setheader ("Location", "");
Response.setheader ("Connection", "close");
%>

7, Apache under 301 redirect Code

Create a new. htaccess file and enter the following (you need to turn on mod_rewrite):

1 Change the domain name without www to the domain name with www

Options +followsymlinks
Rewriteengine on
Rewritecond%{http_host} ^embeta.com [NC]
Rewriterule ^ (. *) $ $ [l,r=301]

2 Redirect to new domain

Options +followsymlinks
Rewriteengine on
Rewriterule ^ (. *) $ $ [l,r=301]

3) using regular 301 steering to achieve pseudo static

Options +followsymlinks
Rewriteengine on
Rewriterule ^news-(. +) \.HTML1
Turn news.php?id=123 Such an address to news-123.html

8, Apache under the vhosts.conf configuration 301 redirect

In order to achieve URL normalization, SEO will usually change the domain name without www to the WWW domain name, vhosts.conf is configured as:

<virtualhost *:80>
ServerName Documentroot/home/embeta
</VirtualHost>
<virtualhost *:80>
ServerName embeta.com
Redirectmatch permanent ^/(. *) $
</VirtualHost>

Apache In addition to the above 2 methods, there are other configuration methods and optional parameters, it is recommended to read the Apache document.

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.