找回密码
 立即注册
首页 程序园 前端 使用php进行301跳转2级域名的代码

使用php进行301跳转2级域名的代码

新程序 2025-5-9 21:13:38
  1. <?php
  2.     $host=$_SERVER['HTTP_HOST'];
  3.     $host=explode(".",$host);
  4.     $count_host=count($host);
  5.     if($count_host==3){
  6.     $host['0'].'.'.$host['2'];
  7.     $ym="http://".$host['0'].".根域名";
  8.     Header("HTTP/1.1 301 Moved Permanently");
  9.     Header("Location: $ym");//你的域名
  10. }
  11. if($count_host==2){
  12.     $ym="http://需要跳转的域名";//你的域名
  13.     Header("HTTP/1.1 301 Moved Permanently");
  14.     Header("Location: $ym");
  15. }
复制代码



您需要登录后才可以回帖 登录 | 立即注册