Home > Backend Development > PHP Problem > How to set up 301 redirect jump in php

How to set up 301 redirect jump in php

coldplay.xixi
Release: 2023-03-08 09:16:02
Original
4179 people have browsed it

How to set 301 redirect jump in php: set the status code [header( "HTTP/1.1 301 Moved Permanently" ); header("Location:your_dest_url")] before the jump.

How to set up 301 redirect jump in php

The operating environment of this tutorial: Windows 7 system, PHP version 5.6, DELL G3 computer. This method is suitable for all brands of computers.

How to set 301 redirect jump in php:

Normal temporary jump in php usually uses:

header("Location:your_dest_url");
Copy after login

This kind of return The status code is 302

If you want to implement php 301 jump, you need to set the status code before:

header( "HTTP/1.1 301 Moved Permanently" ) ; 
header("Location:your_dest_url");
Copy after login

Attachment: 30*The difference between return status codes

  • 301, 302 are both HTTP status codes, and both represent that a certain URL has been transferred. The difference is:

  • 301 redirect: 301 represents permanent transfer. (Permanently Moved),

  • 302 redirect: 302 represents temporary transfer (Temporarily Moved),

  • When these two transfers are used What are the benefits or problems?

  • 301 redirection is the best way to be friendly to search engines after the webpage changes its address. As long as it is not a temporary move, it is recommended to use 301 for redirection.

  • 302 Redirect is a temporary transfer.

Use the above method to achieve php 301 redirection and permanent redirection of the URL.

For example:

<?php
$the_host = $_SERVER[&#39;HTTP_HOST&#39;];//取得当前域名
$request_uri = isset($_SERVER[&#39;REQUEST_URI&#39;]) ? $_SERVER[&#39;REQUEST_URI&#39;] : &#39;&#39;;//判断地址后面是否有参数 
 
header(&#39;HTTP/1.1 301 Moved Permanently&#39;);//发出301头部
header(&#39;Location: http://www.jbxue.com&#39;.$request_uri);//跳转到目标
Copy after login

Related video recommendations: PHP programming from entry to proficiency

The above is the detailed content of How to set up 301 redirect jump in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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