views:

18

answers:

2

What is the best method to combine the following two rules into one, so that users can visit domain.com/schedule and also domain.com/schedule/{day}

The rule should forward to the same controller, where I will then check the parameter

RewriteRule ^schedule/?$ index.php?_orn_shows_action=view-schedule [NC,QSA,L]
RewriteRule ^schedule/([a-zA-Z0-9-]+)/?$ index.php?_orn_shows_action=view-schedule&day=$1 [NC,QSA,L]
A: 

Maybe you don't have to combine it to one - try to switch their positions, second as first and first after that, so your first rule will not catch request that should be analysed by second rule.

killer_PL
A: 

If you don't care whether or not you get the day parameter without a value, you can just do this:

RewriteRule ^schedule(/(([a-zA-Z0-9-]+)/?)?)?$ index.php?_orn_shows_action=view-schedule&day=$3 [NC,QSA,L]

This would capture these variations:

/schedule
/schedule/
/schedule/day
/schedule/day/

If you want to make sure not to get an empty day parameter, do this:

RewriteCond $3      ="" [OR]
RewriteCond &day=$3 ^(.*)$
RewriteRule ^schedule(/(([a-zA-Z0-9-]+)/?)?)?$ index.php?_orn_shows_action=view-schedule&day=$3 [NC,QSA,L]

Finally, if you don't expect to get a query string from the browser on these URLs, I would drop the QSA tag, since someone going to /schedule/monday?day=1 would end up setting day equal to 1, instead of to "monday". There's ways to prevent that, but if you don't need the query string, it's easier just to ignore it.

Tim Stone
That worked great, thanks for that ;-)
Leon Barrett