Reputation: 1272
I want to make a category path with pagination. URL's would be as followed;
All paths should work with or without trailing slash (if possible)
/category/entertainment-and-music/ /category/entertainment-and-music/music/
(represents "music" category "under entertainment and music")
/category/entertainment-and-music/5/
(represents 5th page for "ent. and music")
/category/entertainment-and-music/music/5/
(represents 5th page for "ent. and music/music")
I tried something like that but doesn't work
RewriteRule ^category/(.*)/? /category.php?slug=$1&page=1
RewriteRule ^category/(.*)/(.*)/? /category.php?slug=$1&page=$2
How can I do something flexible like that?
Thanks in advance...
Upvotes: 0
Views: 112
Reputation:
RewriteRule ^category/([A-Za-z0-9_-]+)([/]?)$ /category.php?slug=$1&page=1
RewriteRule ^category/([A-Za-z0-9_-]+)/([0-9]+)([/]?)$ /category.php?slug=$1&page=$2
RewriteRule ^category/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([0-9]+)([/]?)$ /category.php?slug=$1&subcat=$2&page=$3
First rule should cover cases where they just specify a category.
Second rule should cover the category with a page supplied.
Third rule should cover category, sub-category, and page. I wasn't real clear on how you wanted the subcategory populated so I just wrote it out as another argument after slug.
All of them allow for an optional trailing slash.
Upvotes: 2
Reputation: 44132
It looks like your first regex also matches anything that would be caught by your second one.
/category/slugname/7/ would match the .* , with $1 set to "slugname/7"
Try something like this:
RewriteRule ^category/([^/]*)/? /category.php?slug=$1&page=1
RewriteRule ^category/([^/]*)/(.*)/? /category.php?slug=$1&page=$2
At least, or tighten up your matches a bit, like this:
RewriteRule ^category/([a-zA-Z0-9_-]+)/? /category.php?slug=$1&page=1
RewriteRule ^category/([a-zA-Z0-9_-]+)/([0-9]+)/? /category.php?slug=$1&page=$2
That would constrain your slugs to be at least one alphanumeric character, allowing "_" and "-" as well, and your page numbers would have to be, well, numbers.
Upvotes: 1