Iis, apache and PHP page setting 301 redirect jump method_PHP tutorial

WBOY
Release: 2016-07-13 10:48:13
Original
1155 people have browsed it

There are many ways to implement 301 redirection, such as iis, apache, php, asp, etc., you can quickly set up page 301 redirection. Let me introduce it to you.

This article will pass IIS, APACHE, ASP, and PHP servers or page terminals respectively explain how to set up 301 redirection. First, let’s briefly introduce redirection.
301 redirection: refers to a very important "automatic redirection" technology - actually not a technology, that is, URL redirection - when users visit an address or directory, they can specify to jump to another address.
301 redirection, this is the only redirection among all redirection methods that conforms to seo/seo.html" target="_blank">search engine rules. This is also a basic term in SEO, for example: a website uses www.bKjia. When c0m and bKjia.c0m are bound, there will be two weights. If bKjia.c0m is redirected to www.bKjia.c0m, the weights will be concentrated and the weight value will be increased accordingly
.
1. Set up 301 redirection on the IIS server
Preparation work: You must have server setting permissions and you can open a new virtual space at will!
First, create a new virtual space and bind the domain name you need to redirect to;
Second, My Computer-->Open "Control Panel"-->"Administrative Tools"-->Open "Internet Information Services", there will be a tree menu on the left, find your website--right click" Properties"--Select the "Home Directory" tab, then select "Redirect to URL", then enter the target domain name that needs to be directed in the address box, and finally select "Permanent redirection of resources" in the tab and click "OK" to complete the operation. Property interface settings, as shown below:



2. Set apache 301 redirection on the Unix/linux host

Create a new .htaccess file and enter the following content (mod_rewrite needs to be turned on):
1) Forward the domain name without WWW to the domain name with WWW
The code is as follows Copy code
Options +FollowSymLinks
 代码如下 复制代码
Options +FollowSymLinks
RewriteEngine on  RewriteCond %{HTTP_HOST} ^bKjia.c0m [NC]
RewriteRule ^(.*)$www.bKjia.c0m/301/[L,R=301]  
RewriteEngine on RewriteCond %{HTTP_HOST} ^bKjia.c0m [NC]
RewriteRule ^(.*)$www.bKjia.c0m/301/[L,R=301]
2) Redirect to new domain name
 代码如下 复制代码
Options +FollowSymLinks
RewriteEngine on  RewriteRule ^(.*)$www.bKjia.c0m/301/ [L,R=301]
The code is as follows Copy code
Options +FollowSymLinks
RewriteEngine on RewriteRule ^(.*)$www.bKjia.c0m/301/ [L,R=301]
3) Use regular rules to perform 301 redirection to achieve pseudo-static
 代码如下 复制代码
Options +FollowSymLinks
RewriteEngine on  RewriteRule ^article-(.+).html$ article.php?id=  将article.php?id=123这样的地址转向到article-123.html
The code is as follows Copy code
Options +FollowSymLinks RewriteEngine on RewriteRule ^article-(.+).html$article .php?id=$1 Redirect the address like article.php?id=123 to article-123.html

3. Set the 301 redirect code in the ASP program page
In the public header file or global call file, add the following code:
The code is as follows
 代码如下 复制代码

<%@ 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 %>
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 main target URL. If not, redirect
 代码如下 复制代码
$host= 'www.bKjia.c0m'; //你目标定向的网址 
if ($_SERVER['HTTP_HOST'] != $host)//若不是则进行重定向,后面页面参数不变
{ header("HTTP/1.1 301 Moved Permanently"); header("Location: http://{$host}{$_SERVER[REQUEST_URI]}");
}
unset($host);
4. Set 301 redirection in the PHP program page
The code is as follows:

(more perfect way of writing)

The code is as follows Copy code
$host= 'www.bKjia.c0m' ; //Your target URL if ($_SERVER['HTTP_HOST'] != $host)//If not, redirect will be performed, and the subsequent page parameters will remain unchanged { header("HTTP/1.1 301 Moved Permanently"); header("Location: http://{$host}{$_SERVER[REQUEST_URI]}"); } unset($host); Principle: First define the target directional URL, and then determine whether the host currently requested to access is consistent. If not, redirect it
http://www.bkjia.com/PHPjc/632814.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632814.htmlTechArticleThere are many ways to implement 301 redirection, such as iis, apache, php, asp, etc. can all be implemented quickly The settings page has a 301 redirect. Let me introduce to you what this article will teach you...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!