Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

php - Can't figure out mod_rewrite with 2 parameters

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...