调整一个PHP函数,这样它的形式显示链接: - '?/部件PG = 2',而不是'products.php猫= 20安培; PG = 2? [英] Adjusting a php function so that it displays link in the form of:- '/widgets?pg=2' instead of 'products.php?cat=20&pg=2'
问题描述
我增加了以下的.htaccess规则: -
I added the following .htaccess rule:-
RewriteRule ^widgets$ products.php?cat=20 [QSA]
所以,现在我有一个名为小部件简单的链接,导致小工具分类第1页。然而,到了第二页的链接如下所示: -
So now I have a simple link called 'widgets' which leads to the 'widgets' category 1st page. However, the links to the 2nd page looks like the following:-
products.php?cat=20&pg=2
我想是为以后的页面是相当的形式: -
What I would like is for the subsequent pages to be rather in the form of:-
widgets?pg=2
的QSA国旗在上面的.htaccess规则没有做到这一点,但我需要改变函数生成这些页面链接,以获取小工具?PG = 2 $的其他方式的必由之路C $ C>是在浏览器地址栏中键入它: -
mywebsite.com/widgets?pg=2
The QSA flag in the above .htaccess rule does achieve this, but I need to change the function which generates these page links, otherwise the only way of getting to widgets?pg=2
is by typing it in the browser address bar as:- mywebsite.com/widgets?pg=2
.
我觉得下面的PHP函数可能需要进行调整,以达到我想要的结果。任何PHP向导或任何具有相应的知识能帮帮这一点。我想这样做的原因是因为我希望谷歌索引看似简单的网页,而不是较长的: -
I think the following PHP function might need to be adjusted, to achieve the result I want. Can any PHP wizards or anyone with appropriate knowledge please help with this. The reason I want to do this is because I want google to index the simple looking pages, rather than the longer ones:-
function writepagebar($CurPage,$iNumPages,$sprev,$snext,$sLink,$nofirstpage){
$startPage = max(1,round(floor((double)$CurPage/10.0)*10));
$endPage = min($iNumPages,round(floor((double)$CurPage/10.0)*10)+10);
if($CurPage > 1)
$sStr = $sLink . '1' . '" rel="prev"><span style="font-family:Verdana;font-weight:bold">«</span></a> ' . $sLink . ($CurPage-1) . '">'.$sprev.'</a> | ';
else
$sStr = '<span style="font-family:Verdana;font-weight:bold">«</span> '.$sprev.' | ';
for($i=$startPage;$i <= $endPage; $i++){
if($i==$CurPage)
$sStr .= '<span class="currpage">' . $i . '</span> | ';
else{
$sStr .= $sLink . $i . '">';
if($i==$startPage && $i > 1) $sStr .= '...';
$sStr .= $i;
if($i==$endPage && $i < $iNumPages) $sStr .= '...';
$sStr .= '</a> | ';
}
}
if($CurPage < $iNumPages)
$sStr .= $sLink . ($CurPage+1) . '" rel="next">'.$snext.'</a> ' . $sLink . $iNumPages . '"><span style="font-family:Verdana;font-weight:bold">»</span></a>';
else
$sStr .= ' '.$snext.' <span style="font-family:Verdana;font-weight:bold">»</span>';
if($nofirstpage) $sStr = str_replace(array('&pg=1"','?pg=1"'),'" rel="start"',$sStr);
return($sStr);
}
如果它有助于了解如何writepagebar功能融入其本身坐在products.php页面,您可以在这里看到里面的incproducts.php: -
If it helps to know how the writepagebar function fits into the incproducts.php which itself sits inside the products.php page you can see here:-
http://freetexthost.com/3ubiydspzm
推荐答案
后从nitbuntu评论主编: -
在函数只是代替这些行: -
In the function just instead of these lines:-
$sStr = str_replace(array('&pg=1"','?pg=1"'),'" rel="start"',$sStr);
return($sStr);
}
写下面几行: -
write the following lines:-
$sStr = str_replace('products.php?cat=20', 'widgets', $sStr);
$sStr = str_replace('&pg=', '?pg=', $sStr);
$sStr = str_replace(array('&pg=1"', '?pg=1"'), '" rel="start"', $sStr);
return($sStr);
}
希望它帮助。
Hope it helps.
这篇关于调整一个PHP函数,这样它的形式显示链接: - '?/部件PG = 2',而不是'products.php猫= 20安培; PG = 2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!