Solved

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

Posted on 2009-04-04
2
278 Views
Last Modified: 2013-12-14
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
Comment
Question by:Arbuckle2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:Arbuckle2
ID: 24069936
I suppose I could also do this inside a PHP file but i thought .htaccess made more sense.
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 500 total points
ID: 24070887
> 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
I had an issue with InstallShield not being able to use Computer Browser service on Windows Server 2012. Here is the solution I found.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question