PHP在获取页面名称时只在地址栏上显示数据


PHP show data when get page name only on address bar clean urls

www.example.com/category/post/

我的phph文件

if($_GET['category']{
//code here;
}

所以它在我的分类文件中

我的后文件

if($_GET['post']{
// code here;
}

但当我去的那个地址时

www.example.com/category/post/

cate它向我显示了分类页面和后页面中的数据

我想对category页面设置一个if条件,仅当地址包含category并且在它/post/comment/..之后有nore斜杠时才显示数据。。等等,所以它不会显示类别页面的任何数据

我正在使用htaccess进行干净的url

RewriteEngine on
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ index.php?page=$1&&action=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ index.php?page=$1&&action=$2

if($_GET['category']{更改为if($_GET['page']=='category'){

并将if($_GET['post']{更改为if($_GET['action']=='post'){

然后根据自己的意愿在有条件的情况下比赛。

UPD请评论

像这样的写入条件

if(@$_GET['action']!=''){
    if($_GET['action']=='post'){
    //some code for post
    }
}
else if(@$_GET['page']=='category'){
//some code for category
}

对于不同的文件

if(@$_GET['action']=='' && $_GET['page']=='category'){
//some code for category
}