2025年02月23日 建站教程
php如何利用header实现跳转,下面web建站小编给大家详细介绍一下!
浏览器重定跳转
<?php //重定向浏览器 header("Location: https://lmcjl.com"); exit; ?>
浏览器重定跳转
<?php //重定向浏览器 header("Location: https://lmcjl.com"); exit; ?>
404跳转
function getref() { $url = @$_SERVER['HTTP_REFERER']; if( !empty( $url ) ) { if( !strstr($url ,'jb51.net' ) && !strstr($url,'jb51.net')) { @header("http/1.1 404 not found"); @header("status: 404 not found"); include("404.html");//404页面 exit(); } } else { @header("http/1.1 404 not found"); @header("status: 404 not found"); include("404.html");//404页面 exit(); } }
301跳转
<?php $the_host = $_SERVER['HTTP_HOST']; $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; if($the_host !== 'www.jb51.net') { //echo $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; header('HTTP/1.1 301 Moved Permanently'); header('Location: https://www.jb51.net' . $_SERVER['PHP_SELF'] . $request_uri); } ?>
本文链接:http://so.lmcjl.com/news/23687/