我有一个带有buildTrail功能的分页类来显示页码。
为了搜索数据库,这个类工作得很好。
如果我正在搜索“intel”,则第二页链接将为"http://localhost/search/intel/pg/2".
当我尝试过滤结果时出现问题.EX:“http://localhost/search/intel/type/ssd
”因此将显示分页链接:ex“http://localhost/search/intel/type/ssd/intel/type/ssd/pg/2
”
function buildTrail($param = ""){
// $cur_page = basename($_SERVER['PHP_SELF']);
$link = $_SERVER['REQUEST_URI'];
$link_array = explode('/', $link);
//$count = count($link_array);
$pagename = $link_array[1];
// echo $magename;
if(is_array($param)){
foreach($param as $a => $b){
if($a != "page"){
$url .= $pagename."/".$b;
}
}
} else {
$url = $param;
}
$trail = "";
if($this->getPages() > 1){
if($this->getFrom() > 1){
$trail .= "<a href='" . WEBSITE . "/". $url . "/pg/" . $this->getPrevious()."'>«</a>\n ";
}
if($this->getFrom() < 10 && $this->getPages() > 10){
for ($i = 1; $i <= 10; $i++){
$trail .= "<a class='". ($i == $this->getFrom() ? "selected" : "links") . "' href='" . WEBSITE . "/".$url."/pg/" . $i ."'>" . $i . "</a>\n ";
}
} elseif($this->getFrom() < 10 && $this->getPages() < 10){
for ($i = 1; $i <= $this->getPages(); $i++){
$trail .= "<a class='". ($i == $this->getFrom() ? "selected" : "links") . "' href='" . WEBSITE . "/".$url."/pg/" . $i ."'>" . $i . "</a>\n ";
}
}elseif ($this->getFrom() >= 10 && $this->getFrom() <= ($this->getPages() - 5) ){
for ($i = ($this->getFrom() - 5); $i <= ($this->getFrom() + 5); $i ++){
$trail .= "<a class='". ($i == $this->getFrom() ? "selected" : "links") . "' href='" . WEBSITE . "/".$url."/pg/" . $i ."'>" . $i . "</a>\n ";
}
} else {
for ($i = ($this->getPages() - 10); $i <= $this->getPages(); $i ++){
$trail .= "<a class='". ($i == $this->getFrom() ? "selected" : "links") . "' href='" . WEBSITE . "/".$url."/pg/" . $i ."'>" . $i . "</a>\n ";
}
}
if($this->getFrom() < $this->getPages()){
$trail .= "<a href='" . WEBSITE . "/".$url."/pg/" . $this->getNext()."'>»</a>\n ";
}
}
return $trail;
}
答案 0 :(得分:0)
用htaccess解决
RewriteEngine On
Options -Indexes
Options +FollowSymLinks
<Files .htaccess>
deny from all
</Files>
RewriteRule ^search/(.*)/pg/([0-9]+)(/)?$ search.php?page=$2&q=$1 [NC,L]
RewriteRule ^search/(.*)/sort/(.*)/$ search.php?q=$1&sort=$2 [NC,L]
RewriteRule ^search/(.*)/sort/(.*)$ search.php?q=$1&sort=$2 [NC,L]