桃花缘 發表於 2024-1-22 00:00:00

DedeCMS系统301重定向配置方法详解

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        本文实例讲述了DedeCMS系统301重定向配置方法。分享给大家供大家参考。具体实现方法如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        301对于做网站优化的人来讲并不陌生了,像很多网站你访问不带www的会直接跳到www的网址去,这样就会有一个301配置了,如果你用站长工具查会发现是一个301状态代码,这个就是告诉搜索引擎权限给予www,下面我们一起来看看dedecms配置方法,感兴趣的朋友可以实际测试一下.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>一、Linux系统下如何设置301重定向</strong></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        1、建立一个记事本文档,然后点击“文件”--“另存为”,“保存类型”选择“所有文件”,文件名为 .htaccess 就可以,这样不会强制要求输入文件名.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        2、用记事本打开刚才新建的 .htaccess 文件,将下面的代码复制进去:<br>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode3" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        Options +FollowSymLinks <br>
        RewriteEngine on <br>
        rewritecond %{http_host} ^phpfensi <br>
        rewriterule ^(.*)$ http://www.jb51.net/$1 </div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>3、把网址替换成您的网址,然后保存上传你网站的根目录,这个时候你会发现在你IE地址栏里输入根域名就会跳转到www这个域名.</span>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <strong>二、Windows系统下如何设置301重定向并去掉html</strong>,将下面的代码直接替换根目录下面的 index.php 文件,代码如下:<br>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode4" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        &lt;?php <br>
        $HOST=$_SERVER['HTTP_HOST']; <br>
        if ($HOST=="429006.com"|| $HOST==www.jb51.net"{ <br>
        Header("HTTP/1.1 301 Moved Permanently"); <br>
        Header("Location:https://www.jb51.net"); <br>
        exit(); <br>
        } <br>
        if(!file_exists(dirname(__FILE__).'/data/common.inc.php')) <br>
        { <br>
        header('Location:install/index.php'); <br>
        exit(); <br>
        } <br>
        require_once (dirname(__FILE__) . "/include/common.inc.php"); <br>
        require_once DEDEINC."/arc.partview.class.php"; $GLOBALS['_arclistEnv'] = 'index'; <br>
        $row = $dsql-&gt;GetOne("Select * From `dede_homepageset`"); <br>
        $row['templet'] = MfTemplet($row['templet']); <br>
        $pv = new PartView(); <br>
        $pv-&gt;SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . <br>
        $row['templet']); <br>
        $pv-&gt;Display(); <br>
        ?&gt;</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>或者使用下面的代码:</span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode5" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        &lt;?php <br>
        $jump301=1;//是否开启301跳转开关,1开 0关 <br>
        $index_file='index.html';//首页文件 不支持SSI(shtml/shtm) <br>
        if(substr($_SERVER['SERVER_NAME'],0,4)!='www.'&amp;&amp;$jump301) <br>
        { <br>
        header('HTTP/1.1 301 Moved Permanently'); <br>
        header('Location:http://www.'.$_SERVER['SERVER_NAME']); <br>
        exit(); <br>
        } <br>
        if(!file_exists(dirname(__FILE__).'/data/common.inc.php')) <br>
        { <br>
        header('Location:install/index.php'); <br>
        exit(); <br>
        } <br>
        //自动生成HTML版 <br>
        if(isset($_GET['upcache'])) <br>
        { <br>
        require_once (dirname(__FILE__) . "/include/common.inc.php"); <br>
        require_once DEDEINC."/arc.partview.class.php"; <br>
        $GLOBALS['_arclistEnv'] = 'index'; <br>
        $row = $dsql-&gt;GetOne("Select * From `dede_homepageset`"); <br>
        $row['templet'] = MfTemplet($row['templet']); <br>
        $pv = new PartView(); <br>
        $pv-&gt;SetTemplet($cfg_basedir . $cfg_templets_dir . "/" . $row['templet']); <br>
        $pv-&gt;SaveToHtml(dirname(__FILE__).'/'.$index_file); <br>
        include(dirname(__FILE__).'/'.$index_file); <br>
        exit(); <br>
        } <br>
        include(dirname(__FILE__).'/'.$index_file); <br>
        ?&gt;</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>总结:其实最简单办法就是在服务器上做301,比起代码修改要简单很多</span>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
         </p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        希望本文所述对大家的dedecms建站有所帮助。</p>
頁: [1]
查看完整版本: DedeCMS系统301重定向配置方法详解