views:

29

answers:

1

How to add single rewrite rule for-

www.foo.com/tags/tag1 --> www.foo.com/Pages/Articles/ArticleListing.aspx?tags=tag1
www.foo.com/tags/tag1+tag2 --> www.foo.com/Pages/Articles/ArticleListing.aspx?tags=tag1+tag2
www.foo.com/tags/tag1+tag2+tag3 --> www.foo.com/Pages/Articles/ArticleListing.aspx?tags=tag1+tag2+tag3
A: 

Something like the following should work for Apache + mod_rewrite:

 RewriteEngine on
 RewriteRule ^tags/(.*)$ /Pages/Articles/ArticleListing.aspx?tags=$1 [NC,L]

NC = no case sensitivity, L = last rule if this matches

This pattern will match any text after "tags/" and use it as the query parameter "tags". To achieve this, you use the parentheses as a "group" which you can then refer to later using $1 (the first group), any later-precedence parentheses would be considered $2, $3, etc. So you can have multiple matches in one pattern.

You can find the documentation here:

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

John Ewart