CodeOverload
CodeOverload

Reputation: 48485

Mod rewrite with 3 parameters?

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:

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:

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

Answers (3)

TonyCool
TonyCool

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

dchekmarev
dchekmarev

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

Funky Dude
Funky Dude

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

Related Questions