tags:

views:

18

answers:

2

I'm trying to redirect a series of static URLs, and I want it to work whether or not the trailing slash is present:

/foo/bar  --->  /tacos
/foo/bar/  -->  /tacos

I've tried the following, and all sorts of variations, but I always get a match only with the trailing slash present:

RewriteRule ^foo/bar?/$ http://url.com/tacos
RewriteRule ^foo/bar(?/)$ http://url.com/tacos
RewriteRule ^foo/bar*/$ http://url.com/tacos
RewriteRule ^foo/bar(*/)$ http://url.com/tacos

I feel like I'm missing something obvious. Help?

+4  A: 

Other than in EBNF or ABNF, a quantifier in regular expressions refers the the preceding expression and not the following expression. So:

RewriteRule ^foo/bar/?$ http://url.com/tacos
Gumbo
Ha, I knew it was something stupid like that. :) Thanks!
Luke Dennis
+3  A: 

Try

RewriteRule ^foo/bar/?$ http://url.com/tacos
chigley