301 redirection code collection (iis, asp, php, asp.net, apache)

Source: Internet
Author: User

1. Set IIS 301

Internet Information Service Manager-> virtual directory-> redirect to URL, enter the target URL to be redirected, and select "permanent resource redirection ".

In IIS, you can also install the ISAPI Rewrite component to implement the mod_rewrite function in Apache. For details, see ISAPI Rewrite 3 download and common 301 rules.

2. 301 redirection code under ASP

<% @ Language = VBScript %>
<%
Response. Status = "301 Moved Permanently"
Response. AddHeader "Location", "106 /"
%>

3. 301 redirection code under ASP. Net

<Script runat = "server">
Private void Page_Load (object sender, System. EventArgs e)
{
Response. Status = "301 Moved Permanently ";
Response. AddHeader ("Location", "106/");
}
</Script>

4. PHP 301 redirection code

Header ("HTTP/1.1 301 Moved Permanently ");
Header ("Location: 106 /");
Exit ();

5. 301 redirection code under CGI Perl

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

6. 301 redirection code under JSP

<%
Response. setStatus (301 );
Response. setHeader ("Location", "");
Response. setHeader ("Connection", "close ");
%>

7. Apache redirection code 301

Create a new. htaccess file and enter the following content (mod_rewrite must be enabled ):

1) switch the domain name without WWW to the domain name with WWW

Options + FollowSymLinks
RewriteEngine on
RewriteCond % {HTTP_HOST} ^ embeta.com [NC]
RewriteRule ^ (. *) $1 [L, R = 301]

2) redirect to a new domain name

Options + FollowSymLinks
RewriteEngine on
RewriteRule ^ (. *) $1 [L, R = 301]

3) use regular expressions for 301 redirection to achieve pseudo-static

Options + FollowSymLinks
RewriteEngine on
RewriteRule ^ news-(. +) \. html1
Add news. php? Ids0123the address is directed to news-123.html.

8. Configure 301 redirection in vhosts. conf under Apache

To achieve URL standardization, SEO usually redirects a domain name without WWW to a domain name with WWW. The configuration in vhosts. conf is as follows:

<VirtualHost *: 80>
ServerName DocumentRoot/home/embeta
</VirtualHost>
<VirtualHost *: 80>
ServerName embeta.com
RedirectMatch permanent ^/(. *) $1
</VirtualHost>

In addition to the preceding two methods in Apache, there are other configuration methods and optional parameters. We recommend that you read the Apache documentation.

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.