Set the 301 redirect method on the iis, apache, and PHP pages.

Source: Internet
Author: User

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: if a website is bound with and, there will be two weights. If you redirect to, the weights will be concentrated and the weights will be 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. The property page settings are shown in the following figure:

2. Unixhttp: //

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} ^ [NC]
RewriteRule ^ (. *) $[L,R=301]

2) redirect to a new domain name
The code is as follows: Copy code
Options + FollowSymLinks
RewriteEngine on
RewriteRule ^ (. *) $ [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 into article-(.20.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 ")! = "" then
Response. Status = "301 Moved Permanently"
Response. AddHeader "Location", ""
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 '; // 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
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.