PHPCMS手机站伪静态配置指南
首先,进入 /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';
}
接着,打开 /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');
完成代码修改后,需要添加服务器的伪静态重写规则。
若使用 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 手机站伪静态设置的完整流程,希望能对各位有所帮助。如有疑问欢迎留言,小编会及时回复。感谢大家的支持!