I'm using apache's mod_rewrite
to make my application's URL's pretty. I have the basics of mod_rewrite
down pat - several parts of my application use simple and predictable rewrites.
However, I've written a blog function, which use several different parameters.
http://www.somedomain.com/blog/
http://www.somedomain.com/blog/tag/
http://www.somedomain.com/blog/page/2/
I have the following rules in my .htaccess:
RewriteRule ^blog/ index.php?action=blog [NC]
RewriteRule ^blog/(.*) index.php?action=blog&tag=$1 [NC]
RewriteRule ^blog/page/(.*) index.php?action=blog&page=$1 [NC]
However, the rules do not work together. The computer matches the first rule, and then stops processing - even though to my way of thinking, it should not match. I'm telling the machine to match ^blog/
and it goes ahead and matches ^blog/tag/
and ^blog/page/2/
which seems wrong to me.
What's going wrong with my rules? Why are they not being evaluated in the way I'm intending?
Edit: The answer was to terminate the input using $
, and re-order the rules, ever so slightly:
RewriteRule ^blog/$ index.php?action=blog [NC,L]
RewriteRule ^blog/page/(.*)$ index.php?action=blog&page=$1 [NC,L]
RewriteRule ^blog/(.*)$ index.php?action=blog&tag=$1 [NC,L]
These rules produced the desired effect.