问题
I'm building a website with PHP and trying to make RewriteRules.
There is a category page and it has a pagination. Originally, the URL is like
/blog/category.php?category=2&page=2
And I want to redirect this as /blog/category/2/page/2
How can I make this work?
Only for category part, I tried the rules as
RewriteRule ^category/(\d+)$ category.php?category=$1 [NC,L]
but I couldn't figure out how to redirect the page part.
Please help me.
回答1:
Why you don't expand your rewrite rule with the missing page parameter? Then you can access the page. There are a lot more possibilities but i think in your case it's the easiest way.
RewriteRule ^/blog/category/(\d+)/page/(\d+)$ category.php?category=$1&page=$2 [NC,L]
And if you url includes /blog
you should check if you need it in your rewrite rule.
来源:https://stackoverflow.com/questions/51396352/cant-figure-out-mod-rewrite-with-2-parameters