Reputation: 48485
I did tons of methods to figure out how to make this mod rewrite but O was completly unsuccessful.
I want a .htaccess code that rewrite in the following method:
/apple/upcoming/2
→ /handler.php?topic=apple&orderby=upcoming&page=2
This is easy to do, but the problem is that all parameters are not required so the link has different levels of parameters each time like this:
/apple/popular/2
→ /handler.php?topic=apple&orderby=popular&page=2
/apple/2
→ /handler.php?topic=apple&orderby=&page=2
/all/popular/2
→ /handler.php?topic=all&orderby=popular&page=2
/apple/upcoming/
→ /handler.php?topic=apple&orderby=upcoming&page=
So briefly, the URL has 3 optional parameters in one static order: (topic) (orderby) (page)
Note: the ORDERBY parameter can be "popular" or "upcoming" or nothing.
Thanks
Upvotes: 1
Views: 847
Reputation: 1004
For the cases you provided above there rules should work:
RewriteRule ^([^/]+)/(\d+)/?$ handler.php?topic=$1&orderby=&page=$2 [L]
RewriteRule ^([^/]+)/([^/]+)/?$ handler.php?topic=$1&orderby=$2&page= [L]
RewriteRule ^([^/]+)/([^/]+)/(\d+)/?$ handler.php?topic=$1&orderby=$2&page=$3 [L]
Upvotes: 0
Reputation: 459
This should work:
RewriteRule ^([0-9]*)/?$ handler.php?topic=&orderby=&page=$1 [L]
RewriteRule ^(upcoming|popular)/([0-9]*)/?$ handler.php?topic=&orderby=$1&page=$2 [L]
RewriteRule ^([^/]*)/([0-9]*)/?$ handler.php?topic=$1&orderby=&page=$2 [L]
RewriteRule ^([^/]*)/(upcoming|popular)/?$ handler.php?topic=$1&orderby=$2&page= [L]
RewriteRule ^([^/]*)/(upcoming|popular)/([0-9]*)/?$ handler.php?topic=$1&orderby=$2&page=$3 [L]
You should simply declare rewrites in preferred order.
Upvotes: 1
Reputation: 3967
i would suggest redirecting everything after domain name(/apple/upcoming/2) to index.php and from there use php to parse url and call appropriate function.
Upvotes: 1