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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to redirect users to the mobile version of my website using apache based on UserAgent

However if a user chooses to view the full version of the site by clicking on a URL that was the ?ver=full URL parameter, I'd like to stop redirecting them. How can I accomplish this?

The pages are all .html so I don't have the benefit of using php or a similar language.

share|improve this question
Please divulge more information on how you are currently doing the redirect. – Tim Jan 20 '12 at 20:04
up vote 2 down vote accepted

I'm going to go out on a limb and assume that you're redirecting them with mod_rewrite based on their user agent string.

If that's the case, then something like this, added to the condition list:

RewriteCond %{QUERY_STRING} !ver=full [NC]

But, keep in mind that they'd need to keep this parameter in every request they send, including all other links they follow (potentially, depending on your current configuration) requests for static content like images and CSS.. you might want to consider setting a cookie instead of using a URL parameter (or trigger based on either, and set the cookie when the parameter is seen). We can do the cookie through some far more complex mod_rewrite stuff, too - I can assist with that config if that's the direction you'd like to go.

Provide your current configuration and we can talk specifics.

share|improve this answer
I'd like to use a cookie with mod_rewrite. I don't have a current config. I am working on one in this Question… – ckliborn Jan 23 '12 at 21:52

You should investigate Apache's mod_rewrite

Example 4 has a rule for redirecting based on user agent. What you need to add is a condition where this rule is run only if the URL does not contain "?ver=full"

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.