Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

How do you create a conditional redirect using .htaccess based on a query string?

I would like to redirect using my .htaccess based on a particular query string.

if i get a URL like this with "mode=app" in the query string, i'd like to redirect to a new server:
http://stage.example.com/test/?format=json&userid=%1&version=5&mode=ffp

What is the simplest way to do this? I've experimented with redirect, RedirectMatch, RewriteCond, etc but haven't been able to do it.

THANKS!
0
Arbuckle2
Asked:
Arbuckle2
1 Solution
 
Arbuckle2Author Commented:
I suppose I could also do this inside a PHP file but i thought .htaccess made more sense.
0
 
caterham_wwwCommented:
> redirect, RedirectMatch,

Directives from mod_alias can't check the query string. You'll need mod_rewrite:
RewriteEngine on
RewriteCond %{QUERY_STRING} mode_app
RewriteRule ^  http://server2%{REQUEST_URI} [R=301,L]

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now