Solved

Apache Rewrite Rule with Query_String

Posted on 2011-09-22
3
365 Views
Last Modified: 2012-05-12
Hi Experts,

I am trying to force a redirect based on a query parameter.  Let's assume I am redirecting withing the domain test.com.  In plain English I am trying to say:

"If the URL is http://www.test.com/page=94158, then redirect to http://www.test.com/about.htm"

I have this so far:

RewriteCond %{HTTP_HOST} ^(www\.)?test\.com [NC]
RewriteCond %{QUERY_STRING} ^page=94158$
RewriteRule ^(.*)$ http://www.test.com/about.htm [R=302,L]

Open in new window


But my browser is reporting an error that implies that this redirection will create an infinite loop.  

Any suggestions greatly appreciated.
0
Comment
Question by:johnny_f
[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
3 Comments
 
LVL 21

Expert Comment

by:Papertrip
ID: 36584387
hey Johnny,

I'm answering from my phone so I can't get into detail unfortunately, but I managed to get a url copied at least :)  query_string doesn't work exactly like that it needs var=val, but it could if you rewrote that string, but then you might as well just code a hard rewrite :)  sorry for the format from my phone.  wow that took a long time to type :)
http://wiki.apache.org/httpd/RewriteQueryString
0
 
LVL 13

Accepted Solution

by:
dsmile earned 250 total points
ID: 36586079
@johny: it's because ?page=94158 is automatically appended to the end of about.htm, so your rule will create an infinite loop

Just add ? after .htm on line 3
RewriteCond %{HTTP_HOST} ^(www\.)?test\.com [NC]
RewriteCond %{QUERY_STRING} ^page=94158$
RewriteRule ^(.*)$ http://www.test.com/about.htm? [R=302,L]

Open in new window

0
 

Author Comment

by:johnny_f
ID: 36587095
Hi DSmile,

Bingo - thank you very much.  So close and yet so far.  So that I understand, would it be accurate to say that (a) the default behavior is to append the query string to the end of the new URL so (b) the ? char at the end not only indicates the end of the line, but forces the end of the line?

Thanks for your time Papertrip.

John
0

Featured Post

Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

Question has a verified solution.

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

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

617 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