My base url looks like this.
http://localhost/test/s/beer-drinks
And depending on the users input it can be something like this.
http://localhost/test/s/beer-New-York-drinks_alcoholic-No_rating-2-3_price-1-3_page-2
The part where it says "beer" can be any string which is the actual search string the user inputs.
The part where it says "New-York" can be any city and the user has an option of setting or not setting it.
The user also has the option of setting or not setting values for the following. alcoholic can have a value of No or Yes rating can either be a value from 1 to 5 and multiple values are separated by a - price can either be a value from 1 to 5 and multiple values are separated by a - page is a number indicating the offset for pagination
I wanted to direct the url above and be able to pass the values for the actual search string ("beer"), neglect the match for the city and pass the values for alcoholic, rating, price and page if the are set.
I have something like this on my htaccess
RewriteRule ^search$ s/ [R=301,L]
RewriteRule ^search/$ s/ [R=301,L]
RewriteRule ^s/(.*)-drinks_alcoholic-(.*)_rating-(.*)_price-(.*)_page-(.*) search/q_$1/alcoholic_$2/rating_$3/price_$4/page_$5/
.
.
.
RewriteRule ^s/(.*)-drinks_page-(.*) search/q_$1/page_$2/
RewriteRule ^s/(.*)-drinks search/q_$1/
I am having a hard time matching the city part without breaking the order of the matches ($1, $2, etc).
I found this article which explains conditionals in regex patterns but i can seem to get it to work specially if page is set.