Home Backend Development PHP Tutorial Iis, apache and PHP page setting 301 redirect jump method_PHP tutorial

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

Jul 13, 2016 am 10:48 AM
301 apache iis php Method Can and accomplish method have set up Jump Redirect page

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...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

How to set the cgi directory in apache How to set the cgi directory in apache Apr 13, 2025 pm 01:18 PM

To set up a CGI directory in Apache, you need to perform the following steps: Create a CGI directory such as "cgi-bin", and grant Apache write permissions. Add the "ScriptAlias" directive block in the Apache configuration file to map the CGI directory to the "/cgi-bin" URL. Restart Apache.

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

What to do if the apache80 port is occupied What to do if the apache80 port is occupied Apr 13, 2025 pm 01:24 PM

When the Apache 80 port is occupied, the solution is as follows: find out the process that occupies the port and close it. Check the firewall settings to make sure Apache is not blocked. If the above method does not work, please reconfigure Apache to use a different port. Restart the Apache service.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

How to view your apache version How to view your apache version Apr 13, 2025 pm 01:15 PM

There are 3 ways to view the version on the Apache server: via the command line (apachectl -v or apache2ctl -v), check the server status page (http://&lt;server IP or domain name&gt;/server-status), or view the Apache configuration file (ServerVersion: Apache/&lt;version number&gt;).

See all articles