Can't figure out mod_rewrite with 2 parameters

a 夏天 提交于 2019-12-13 09:22:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!