[英]How to rewrite url in php using htaccess file
pagination is not working after adding .htaccess file on my project. 在我的项目上添加.htaccess文件后,分页不起作用。
Code for Paging is : 分页代码为:
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
when i click on categories link it display 100 categories and url is 当我单击类别链接时,它显示100个类别,URL为
hostname/site1/categories 主机名/站点1 /类别
but when i click on next link it will display same content of 100 categories and url is 但是,当我单击下一个链接时,它将显示100个类别的相同内容,URL为
hostname/site1/categories/page/0 主机名/站点1 /类别/页/ 0
I got answer of my question and i am posting here because help to other developer to have same question. 我得到了我问题的答案,我在这里发布是因为帮助其他开发人员也有同样的问题。
If you have same quote.php page and your urls like 如果您有相同的quote.php页面,并且您的网址像
site1/testing/quote/category/ site1 / testing / quote / category /
site1/testing/quote/category/love-quotes site1 / testing / quote / category / love-quotes
site1/testing/quote/category/love-quotes/page/1 site1 / testing / quote / category / love-quotes / page / 1
and add those rules on your .htaccess file. 并将这些规则添加到您的.htaccess文件中。
RewriteRule quote/category/(. )/page/(. )/ quote.php?category=$1&page=$2 [NS] 重写规则报价/类别/(。)/页/(。)/ quote.php?类别= $ 1页= $ 2 NS]
RewriteRule quote/category/(. )/page/(. ) quote.php?category=$1&page=$2 [NS] 重写规则报价/类别/(。)/页/(。)quote.php?类别= $ 1页= $ 2 NS]
RewriteRule quote/category/(.*)/$ quote.php?category=$1 [L] RewriteRule quote / category /(.*)/$ quote.php?category = $ 1 [L]
RewriteRule quote/category/(.*)$ quote.php?category=$1 [L] RewriteRule quote / category /(.*)$ quote.php?category = $ 1 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.