Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a rewrite map that has some keys with query strings and some without.

Is it possible to pass in the key based on the request depending on if it has a query string or not?

My current rewrite rules are:

# Search in the map.
RewriteCond ${map_name:/$1?%{QUERY_STRING}|not-found} ^(.+)$   
# Make sure it was found.
RewriteCond %1 !^not-found$
RewriteRule ^(.+)$ http://www.domain.com${map_name:/$1?%{QUERY_STRING}} [R=301,L]

What the above does is if a key is found, redirect to the key's value.

It works for URLs/keys with query strings. If I remove the ? it will work for URLs without query strings. How can I do both without simply duplicating the condition and removing the question mark?

A sample map

/recipes/?id=5  /new/recipe/url
/about-us       /new/about

There are hundreds of these, so I need to be able to search for keys with query strings and without, and I'm not sure if I'm tackling this the right way.

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.