Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...