[英]How to rewrite url in php using htaccess file
在我的项目上添加.htaccess文件后,分页不起作用。
分页代码为:
if ($page > 0) {
$last = $page - 2;
echo "<a href=" . $this->SITE_URL . "categories/page/$last>Previous</a>";
echo "<a href=" . $this->SITE_URL . "categories/page/$page>Next</a>";
} else if ($page == 0) {
echo "<a href=" . $this->SITE_URL . "categories/page/$page>Next</a>";
} else if ($left_rec < $rec_limit) {
$last = $page - 2;
echo "<a href=" . $this->SITE_URL . "categories/page/$last>Previous</a>";
}
.htaccess file have
RewriteRule categories category.php
RewriteRule categories/page/(.*)/ category.php?page=$1
RewriteRule categories/page/(.*) category.php?page=$1
当我单击类别链接时,它显示100个类别,URL为
主机名/站点1 /类别
但是,当我单击下一个链接时,它将显示100个类别的相同内容,URL为
主机名/站点1 /类别/页/ 0
我得到了我问题的答案,我在这里发布是因为帮助其他开发人员也有同样的问题。
如果您有相同的quote.php页面,并且您的网址像
site1 / testing / quote / category /
site1 / testing / quote / category / love-quotes
site1 / testing / quote / category / love-quotes / page / 1
并将这些规则添加到您的.htaccess文件中。
重写规则报价/类别/(。)/页/(。)/ quote.php?类别= $ 1页= $ 2 NS]
重写规则报价/类别/(。)/页/(。)quote.php?类别= $ 1页= $ 2 NS]
RewriteRule quote / category /(.*)/$ quote.php?category = $ 1 [L]
RewriteRule quote / category /(.*)$ quote.php?category = $ 1 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.