Solved

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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.
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

792 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