首页 > 开发 > Php > 正文

301重定向代码(php apache)

2020-06-09 12:51:32
字体:
来源:转载
供稿:网友

使用 HTACCESS 文件 添加吧,这是代码:

  1. Options +FollowSymLinks 
  2. RewriteEngine on 
  3. RewriteCond %{HTTP_HOST} ^domain.com[NC] 
  4. RewriteRule ^(.*)$ http://www.Cuoxin.com/$1 [L,R=301

php写法:

  1. <? 
  2. Header( "HTTP/1.1 301 Moved Permanently" ); 
  3. Header( "Location: www.Cuoxin.com" ); 
  4. ?> 

不带index.php文件:

  1. <?php 
  2. $qurl = $_SERVER['REQUEST_URI']; 
  3. //获取url,伪静态地址也能完整取得 
  4. $qurl = str_replace("/index.php","",$qurl); 
  5. if ($qurl!=""){ 
  6. header("HTTP/1.1 301 Moved Permanently"); 
  7. header("Location: http://www.Cuoxin.com"); 
  8. exit();} 
  9. ?> 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表