这篇文章运用简单易懂的例子给大家介绍如何设置phpcms手机站首页伪静态,代码非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
phpcms手机站首页设置伪静态的方法:
1、打开/phpcms/modules/wap/functions/global.func.php
找到里面的这两个函数,如下图所示的注释掉的那行代码,在下面加入一行代码。
function list_url($typeid) {
#return WAP_SITEURL."&a=lists&typeid=$typeid";
return "/list-$typeid".'.html';
}
function show_url($catid, $id, $typeid='') {
global $WAP;
if($typeid=='') {
$types = getcache('wap_type','wap');
foreach ($types as $type) {
if($type['cat']==$catid) {
$typeid = $type['typeid'];
break;
}
}
}
#return WAP_SITEURL."&a=show&catid=$catid&typeid=$typeid&id=$id";
return "/show-$catid-$typeid-$id-1".'.html';
}
2、打开/phpcms/modules/wap/index.php
找到第59行,如下图所示的注释掉的那行代码,在下面加入一行代码。
#define('URLRULE', 'index.php?m=wap&c=index&a=lists&typeid={$typeid}~index.php?m=wap&c=index&a=lists&typeid={$typeid}&page={$page}');
define('URLRULE', 'list-{$typeid}.html~list-{$typeid}-{$page}.html');
3、添加伪静态规则
我使用的是apache服务器,把apache服务器设置支持.htaccess文件,在网站根目录创建.htaccess文件,在里面添加代码:
RewriteEngine On
RewriteRule ^list-([0-9]+)-([0-9]+) index.php?&a=lists&typeid=$1&page=$2
RewriteRule ^list-([0-9]+) index.php?&a=lists&typeid=$1;
RewriteRule ^show-([0-9]+)-([0-9]+)-([0-9]+) index.php?a=show&catid=$1&typeid=$2&id=$3;
这样,phpcms手机站就变成伪静态了。
.htaccess如何设置和创建可自行百度一下,方法都比较简单,这里就不细说了。
如果是nginx服务器,重写规则这样写:
rewrite ^/list-([0-9]+).html /index.php?&a=lists&typeid=$1 last;
rewrite ^/show-([0-9]+)-([0-9]+)-([0-9]+)-1.html /index.php?a=show&catid=$1&typeid=$2&id=$3 last;
关于如何设置phpcms手机站首页伪静态就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。