There are many ways to achieve 301 redirection, such as iis, apache, php, asp, and so on, you can quickly set page 301 redirection. Next I will introduce you
This article explains how to set 301 redirection on IIS, APACHE, ASP, and PHP servers or page programs.
301 redirection: it refers to a very important "automatic redirection" technology-in fact, it is not a technology, that is, URL redirection-the user can access an address or directory and specify to jump to another address.
301 redirection. This is the only redirection in all redirection methods that meets the seo/seo.html "target =" _ blank "> Search Engine rules. This is also a basic term in SEO. For example: www. bKjia. c0m, bKjia. c0m binding, there will be two weights, if bKjia. c0m redirection to www. bKjia. c0m, the weight is concentrated, and the weight value is increased accordingly.
1. Set 301 redirection on the IIS server
Preparations: You need to have the server settings permission to activate a new virtual space at will!
First, create a virtual space and bind the domain name you want to redirect to with its resolution;
Second, my computer --> open "Control Panel" --> "Management Tools" --> open "Internet Information Service", with a tree menu on the left, find your website, right-click "properties", select the "home directory" tab, select "redirect to URL", and enter the target domain name to be targeted in the address box, finally, select "permanent resource redirection" on the tab and click "OK" to complete the operation. Shows the property interface settings:
2. Set 301 redirection for apache on Unix/linux Hosts
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
The Code is as follows: |
Copy code |
Options + FollowSymLinks RewriteEngine on RewriteCond % {HTTP_HOST} ^ bKjia. c0m [NC] RewriteRule ^ (. *) $ www. bKjia. c0m/301/[L, R = 301] |
2) redirect to a new domain name
The Code is as follows: |
Copy code |
Options + FollowSymLinks RewriteEngine on RewriteRule ^ (. *) $ www. bKjia. c0m/301/[L, R = 301] |
3) use regular expressions for 301 redirection to achieve pseudo-static
The Code is as follows: |
Copy code |
Options + FollowSymLinks RewriteEngine on RewriteRule implements article-(.w.20..html $ article. php? Id = $1 Set article. php? Id=123the address is directed to article-123.html. |
3. Set the 301 redirection code on the ASP program page
Add the following code to a public header file or a global call file:
The Code is as follows: |
Copy code |
<% @ Language = VBScript %> <% If request. ServerVariables ("SERVER_NAME ")! = "Www. bKjia. c0m" then Response. Status = "301 Moved Permanently" Response. AddHeader "Location", "http://www.bKjia. c0m" Response. End end if %> |
Principle: Determine whether the requested server_name is the same as the primary target URL. If not, redirect
4. Set 301 redirection on the PHP program page
The Code is as follows: (perfect syntax)
The Code is as follows: |
Copy code |
$ Host = 'www. bKjia. c0m'; // your target URL If ($ _ SERVER ['HTTP _ host']! = $ Host) // If not, the system redirects and the parameters on the subsequent pages remain unchanged. {Header ("HTTP/1.1 301 Moved Permanently"); header ("Location: http: // {$ host} {$ _ SERVER [REQUEST_URI]}"); } Unset ($ host ); |
Principle: first define the target targeted URL, and then determine whether the currently requested hosts are consistent. If yes, redirect