How to implement 301 redirect in php

WBOY
Release: 2016-07-25 09:03:37
Original
1019 people have browsed it
  1. $the_host = $_SERVER['HTTP_HOST']; //Mark to get the current domain name
  2. $request_url = isset($_SERVER['REQUEST_URI'])?$_SERVER['REQUEST_URI']: ''; //Determine the last part of the address
  3. if($the_host !== 'bbs.it-home.org') //The domain name address that has not been changed
  4. {
  5. header('HTTP/1.1 301 Moved Permanently'); / / Prompt to issue 301
  6. header('Location: http://bbs.it-home.org/'.$request_url); //Add new domain name address
  7. }
  8. ?>
Copy code

2. In which file should you add the 301 redirect command Add 301 redirect instructions to the .htaccess file and use mod_rewrite (url rewriting) technology. Example:

  1. RewriteEngine on
  2. RewriteRule ^(.*)$ http://bbs.it-home.org/$1 [R=301,L]
Copy code


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