Home php教程 php手册 PHP代码实现301跳转页面实例

PHP代码实现301跳转页面实例

May 25, 2016 pm 04:50 PM
php code Example

301跳转就是告诉访问者页面己经永远到了新的页面了,在php中使用301跳转我们利用header()函数发送301状态代码告诉浏览器,然后再实现页面跳转即可。

PHP纯代码跳转,代码如下:

<?php
header("Location:http://www.phprm.com/");
?>
Copy after login

但是这种返回的状态码是302,如果要实现301跳转的话,需要在之前设置下状态码,代码如下:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location:http://www.phprm.com/");
?>
Copy after login

更简单的PHP跳转301代码,代码如下:

<?php
$urlto = &#39;http://www.phprm.com/&#39;;
header(&#39;Location: &#39; . $urlto, TRUE, 301);
?>
Copy after login

可能出现的问题

Warning: Cannot modify header information - headers already sent by把文件编码改成 UTF-8无BOM格式,可解决该问题,如果还是有问题,就检查下该代码前是否定义了字符串变量,删除这个变量再试试。

附:30*返回状态码的区别

301,302 都是HTTP状态的编码,都代表着某个URL发生了转移,不同之处在于:

1.301 redirect: 301 代表永久性转移(Permanently Moved)

2.302 redirect: 302 代表暂时性转移(Temporarily Moved )

这两种转移在使用的时候有啥好处或者问题?

301 重定向是网页更改地址后对seo搜索引擎友好的最好方法,只要不是暂时搬移的情况,都建议使用301来做转址。

302 重定向是临时性转移。

本文地址:

转载随意,但请附上文章地址:-)

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

SVM examples in Python SVM examples in Python Jun 11, 2023 pm 08:42 PM

Support Vector Machine (SVM) in Python is a powerful supervised learning algorithm that can be used to solve classification and regression problems. SVM performs well when dealing with high-dimensional data and non-linear problems, and is widely used in data mining, image classification, text classification, bioinformatics and other fields. In this article, we will introduce an example of using SVM for classification in Python. We will use the SVM model from the scikit-learn library

VUE3 Getting Started Example: Making a Simple Video Player VUE3 Getting Started Example: Making a Simple Video Player Jun 15, 2023 pm 09:42 PM

As the new generation of front-end frameworks continues to emerge, VUE3 is loved as a fast, flexible, and easy-to-use front-end framework. Next, let's learn the basics of VUE3 and make a simple video player. 1. Install VUE3 First, we need to install VUE3 locally. Open the command line tool and execute the following command: npminstallvue@next Then, create a new HTML file and introduce VUE3: &lt;!doctypehtml&gt;

How to use regular expressions to batch modify PHP code to meet the latest code specifications? How to use regular expressions to batch modify PHP code to meet the latest code specifications? Sep 05, 2023 pm 03:57 PM

How to use regular expressions to batch modify PHP code to meet the latest code specifications? Introduction: As time goes by and technology develops, code specifications are constantly updated and improved. During the development process, we often need to modify old code to comply with the latest code specifications. However, manual modification can be a tedious and time-consuming task. In this case, regular expressions can be a powerful tool. Using regular expressions, we can modify the code in batches and automatically meet the latest code specifications. 1. Preparation: before using

Verification code usage examples in Gin framework Verification code usage examples in Gin framework Jun 23, 2023 am 08:10 AM

With the popularity of the Internet, verification codes have become a necessary process for login, registration, password retrieval and other operations. In the Gin framework, implementing the verification code function has become extremely simple. This article will introduce how to use a third-party library to implement the verification code function in the Gin framework, and provide sample code for readers' reference. 1. Install dependent libraries Before using the verification code, we need to install a third-party library goCaptcha. To install goCaptcha, you can use the goget command: $goget-ugithub

The relationship between the number of Oracle instances and database performance The relationship between the number of Oracle instances and database performance Mar 08, 2024 am 09:27 AM

The relationship between the number of Oracle instances and database performance Oracle database is one of the well-known relational database management systems in the industry and is widely used in enterprise-level data storage and management. In Oracle database, instance is a very important concept. Instance refers to the running environment of Oracle database in memory. Each instance has an independent memory structure and background process, which is used to process user requests and manage database operations. The number of instances has an important impact on the performance and stability of Oracle database.

VAE algorithm example in Python VAE algorithm example in Python Jun 11, 2023 pm 07:58 PM

VAE is a generative model, its full name is VariationalAutoencoder, which is translated into Chinese as variational autoencoder. It is an unsupervised learning algorithm that can be used to generate new data, such as images, audio, text, etc. Compared with ordinary autoencoders, VAEs are more flexible and powerful and can generate more complex and realistic data. Python is one of the most widely used programming languages ​​and one of the main tools for deep learning. In Python, there are many excellent machine learning and deep

Learn best practice examples of pointer conversion in Golang Learn best practice examples of pointer conversion in Golang Feb 24, 2024 pm 03:51 PM

Golang is a powerful and efficient programming language that can be used to develop various applications and services. In Golang, pointers are a very important concept, which can help us operate data more flexibly and efficiently. Pointer conversion refers to the process of pointer operations between different types. This article will use specific examples to learn the best practices of pointer conversion in Golang. 1. Basic concepts In Golang, each variable has an address, and the address is the location of the variable in memory.

PHP simple web crawler development example PHP simple web crawler development example Jun 13, 2023 pm 06:54 PM

With the rapid development of the Internet, data has become one of the most important resources in today's information age. As a technology that automatically obtains and processes network data, web crawlers are attracting more and more attention and application. This article will introduce how to use PHP to develop a simple web crawler and realize the function of automatically obtaining network data. 1. Overview of Web Crawler Web crawler is a technology that automatically obtains and processes network resources. Its main working process is to simulate browser behavior, automatically access specified URL addresses and extract all information.

See all articles