温馨提示×

apache如何做301跳转

小新
182
2020-12-23 18:04:46
栏目: 编程语言

apache如何做301跳转

apache做301跳转的示例:

1.建立一个301.php文件,代码如下:

<?php

$the_host  =  $_SERVER [ 'HTTP_HOST' ]; //取得当前域名

$the_url  = isset( $_SERVER [ 'REQUEST_URI' ]) ?  $_SERVER [ 'REQUEST_URI' ] :  '' ; //判断地址后面部分

$the_url  =  strtolower ( $the_url ); //将英文字母转成小写

if ( $the_url == "/index.php" ) //判断是不是首页

{

$the_url = "" ; //如果是首页,赋值为空

}

if ( $the_host  !==  'www.icoa.cn' ) //如果域名不是带www的网址那么进行下面的301跳转

{

header( 'HTTP/1.1 301 Moved Permanently' ); //发出301头部

header( 'Location:http://www.icoa.cn' . $the_url );//跳转到带www的网址

}

?>

2.在对应网页文件中调用301.php即可,代码如下:

<?php  include ( "301.php" );  //301重定向 ?>

0