网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 生活知识 知识问答

dedecms (织梦)实现301永久重定向代码几种方法

时间:2024-10-13 11:09:31

1、在index.php 头部插入以下代码if(substr($_SERVER['HT哌囿亡噱TP_HOST'],0,3) != 'www') { header('HTTP/1.1 301 Moved Permanently'); header('Location:http://www.'.$_SERVER['HTTP_HOST']); exit(); }或者<?php if(substr($_SERVER['HTTP_HOST'],0,3) != 'www') { header('HTTP/1.1 301 Moved Permanently'); header('Location: http://www.'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); } ?>

2、需要注意的是如果你用的IIS请在文觇致惯鸹档优先级中设index.php为默认首页,这样才能先读取php,代码才能生效,以我的域名为例,我是将带www的重定向到不带www域,反之,同理。代码如下:<?php$HOST=$_SERVER['HTTP_HOST'];if ($HOST=="网址.com"){Header("HTTP/1.1 301 Moved Permanently");Header("Location:http://www.网址.com");exit();}if(!file_exists(dirname(__FILE__).'/data/common.inc.php')){ header('Location:install/index.php'); exit();}//自动生成HTML版require_once (dirname(__FILE__) . "/include/common.inc.php");require_once DEDEINC."/arc.partview.class.php";$GLOBALS['_arclistEnv'] = 'index';$row = $dsql->GetOne("Select * From`dede_homepageset`");$row['templet'] = MfTemplet($row['templet']);$pv = new PartView();$pv->SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $row['templet']);$pv->Display();?>

3、当然如何你的虚拟主机支持URL重现最好使用下面办法 针对APACHE服务器在.htaccess文件里写上以下代码即可。没有.htaccess新建一个即可RewriteEngine on RewriteCond %{HTTP_HOST} !^(.*)\.网址\.com$ [NC] RewriteRule ^(.*)$ http://www.网址.com/ $1 [L,R=301]

© 2026 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com