How to Implement 301 redirection (apache/iis/htaccess) for websites

Source: Internet
Author: User

From the perspective of search engine optimization, the 301 redirection technology is undoubtedly the best way to handle changes to the website URL, while the 301 permanent redirection, it is nothing more than the safest and most perfect solution for many redirection technologies.

1) IIS 301 redirection

IIS implements 301 permanent redirection. This method is applicable to Windows servers. perform the following operations in sequence: in IIS, right-click the corresponding website and choose "redirect to URL"> "redirect to", enter the URL address of the target webpage, and select "permanent resource redirection" (check here) -> "application.

2) Apache 301 redirection

Apache server implements 301 redirection. The "mod_rewrite" pseudo-static technology is usually used, and the. htaccess file is used here. Using domain name 301 redirection to a second-level domain name of www as an example, you only need to add the following rules to the. htaccess file:
Options + FollowSymLinks

The Code is as follows: Copy code
RewriteEngine on
RewriteCond % {HTTP_HOST} ^ xp-sem.com
RewriteRule ^ (. *) $ http://www.xp-sem.com/#1 [R = permanent, L]
Similarly, the pseudo-static technology of Windows server can also achieve 301 redirection. You only need to add the following rules to httpd. ini:
RewriteCond Host: ^ xp-sem.com $
RewriteRule (. *) http://www.xp-sem.com $1 [R, I]

3) redirection in Linux 301

The Code is as follows: Copy code
Redirect 301/http://www.xp-sem.com/

This is a commonly used method. You can use this command to tell the search engine spider that your site file is not in this URL.


4) PHP 301 redirection
Add the following code to the webpage header:

The Code is as follows: Copy code
<? Php
Header ("HTTP/1.1 301 Moved Permanently ");
Header ("Location: http://www.xp-sem.com ");
?>

5) ASP 301 redirection
<% @ Language = VBScript %>
<%
Response. Status = "301 Moved Permanently"
Response. AddHeader "Location", "http://www.xp-sem.com"
%>

6) ASP. NET 301 redirection

The Code is as follows: Copy code
<Script runat = "server">
Private void Page_Load (object sender, System. EventArgs e)
{
Response. Status = "301 Moved Permanently ";
Response. AddHeader ("Location", "http://www.xp-sem.com ");
}
</Script>

7)

ColdFusion 301 redirection

The Code is as follows: Copy code
<. Cfheader statuscode = "301" statustext = "Moved permanently">
<. Cfheader name = "Location" value = "http://www.xp-sem.com">

8) bind/local DNS (Domain Name alias jump) 301 redirection
If you have domain name DNS control panel management permissions, you only need to add an alias record to achieve 301 redirection.
For example, to direct the blog.xp-sem.com to a www.xp-sem.com, you just need to add an alias record IN the DNS service, which can be written as: blog in cname www.xp-sem.com;
If you need to configure a large number of virtual domain names, you can write it as: * in cname www.xp-sem.com, so that you can redirect all records that are not set to end with a xp-sem.com to the www.xp-sem.com.

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.