首页 > CMS建站 > Phpwind > 正文

PhpWind教程:伪静态之简单而强大设置教程(美观浏览地址)修正圣诞版本

2020-05-30 21:53:57
字体:
来源:转载
供稿:网友

不可否认,Rewrite 受到很多站长的喜欢,也受几个大的搜索引擎所亲睐,在7版本升级之际把这个传说中的神秘方法分享给大家,先看下案例  ,如dedecms,huodao等论坛的伪静态,下面是ST的
板块访问地址:http://www.stwind.org/_22
帖子访问地址:http://www.stwind.org/r5764.html   (完全可以做到/5764.html,按个人喜好!)

说明:由于win和unix的差异,之前版本在win机器IIS下兼容不好,比如导致头像下载问题,感谢蓝冰宝宝反馈问题。
一下版本以及文件是修正过的圣诞版本,可以兼容IIS/apache/.htaccess,如果不成功可以回帖说明!
                  
下面开始教程分享,使用的前提条件是 支持Rewrite 可以在IIS/apache/nginx      以及虚拟主机的上的 .htaccess。
第一步:
添加规则
IIS/apache/.htaccess

这说明下,服务器端的-》 IIS的伪静态配置文件为httpd.ini ,apache的的配置文件为 httpd.conf,  虚拟主机支持为静态的文件为 .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/f_(.*)_(.*)$ $1/thread.php?fid=$2&page=$3
RewriteRule ^(.*)/f_(.*)$      $1/thread.php?fid=$2&page=$3
RewriteRule ^(.*)/(.*)_(.*)_(.*).html$  $1/read.php?tid=$2&page=$3&fpage=$4 
RewriteRule ^(.*)/(.*)_(.*).html$       $1/read.php?tid=$2&page=$3&fpage=$4 
RewriteRule ^(.*)/(.*).html$         $1/read.php?tid=$2
</IfModule>
nginx
rewrite ^(.*)/f_(.*)_(.*)$ $1/thread.php?fid=$2&page=$3 last;
rewrite ^(.*)/f_(.*)$      $1/thread.php?fid=$2 last;
rewrite ^(.*)/(.*)_(.*)_(.*).html$  $1/read.php?tid=$2&page=$3&fpage=$4  last;
rewrite ^(.*)/(.*)_(.*).html$       $1/read.php?tid=$2&page=$3  last;
rewrite ^(.*)/(.*).html$         $1/read.php?tid=$2 last;
rewrite ^(.*)-htm-(.*)$ $1.php?$2 last;

第二步:
打开global.php 找到

function Htm_cv($url,$tag){
    global $db_dir,$db_ext;
    if (!preg_match('/^(http|ftp|telnet|mms|rtsp)|admin.php|rss.php/i',$url)) {
        $tmppos = strpos($url,'#');
        $add = $tmppos!==false ? substr($url,$tmppos) : '';
        $url = str_replace(
            array('.php?','=','&',$add),
            array($db_dir,'-','-',''),
            $url
        ).$db_ext.$add;
    }
    return stripslashes($tag)."$url/"";
}
替换成
function Htm_cv($url, $tag){//modify By Josh
     global $db_dir, $db_ext;
     if (!preg_match('/^(http|ftp|telnet|mms|rtsp)|admin.php|rss.php/i', $url)){
         $add = strpos($url, '#') !== false ? substr($url, strpos($url, '#')) : '';
         if(strpos($url, 'thread.php?') !== false){
             unset($rw); //$rw type  $ru  array
             $tharr = explode('&', substr(str_replace($add, '', $url), 11));
             foreach($tharr as $key => $value){
                 $ru = explode('=', $value, 2);
                 if($ru['1']){
                     switch($ru['0']){
                     case 'fid':
                         $rw['fid'] = $ru['1'];
                         $rw['type'] < 1 && $rw['type'] = 1;
                         break;
                     case 'page':
                         $rw['page'] = $ru['1'];
                         $rw['type'] < 2 && $rw['type'] = 2;
                         break;
                     default:
                         $rw['type'] = 4;
                         $urlfail = 1;
                         break;
                         }
                     }
                 }
             switch($rw['type']){
             case '1':
                 $url = "f_" . $rw['fid'] ;
                 break;
             case '2':
                 $url = "f_" . $rw['fid'] . "_" . $rw['page'] ;
                 break;
                 }
             }elseif(strpos($url, 'read.php?') !== false){
             unset($rw);
             $rarr = explode('&', substr(str_replace($add, '', $url), 9));
             foreach($rarr as $key => $value){
                 $ru = explode('=', $value, 2);
                 if($ru['1']){
                     switch($ru['0']){
                     case 'tid':
                         $rw['tid'] = $ru['1'];
                         $rw['type'] < 1 && $rw['type'] = 1;
                         break;
                     case 'page':
                         $rw['page'] = $ru['1'];
                         $rw['type'] < 2 && $rw[type] = 2;
                         break;
                     case 'fpage':
                         $rw['fpage'] = $ru['1'];
                         $rw['type'] < 3 && $rw['type'] = 3;
                         break;
                     default:
                         $rw['type'] = 4;
                         $urlfail = 1;
                         break;
                         }
                     }
                 }
             switch($rw['type']){
             case '1':
                 $url = $rw['tid'] . ".html";
                 break;
             case '2':
                 $url = $rw['tid'] . "_" . $rw['page'] . ".html";
                 break;
             case '3':
                 $url = $rw['tid'] . "_" . $rw['page'] . "_" . $rw['fpage'] . ".html";
                 break;
                 }
             }
         if($urlfail){
             $url = str_replace(
                array('.php?', '=', '&', $add),
                 array($db_dir, '-', '-', ''),
                 $url
                ) . $db_ext . $add;
             }
         }
     return stripslashes($tag) . "$url/"";
    }

OK,修改完成,开始享受你的伪静态吧~!~



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

图片精选