Solved

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

Posted on 2009-04-04
2
263 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
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
capture pcap with filtered traffic 1 65
Does SSL have any bearing on connections via http on port 80? 3 33
ERR_NAME_NOT_RESOLVED 7 19
QQ problem 22 23
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

777 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