Solved

Apache Rewrite Rule with Query_String

Posted on 2011-09-22
3
347 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
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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now