Solved

Apache Rewrite Rule with Query_String

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
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, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 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

19 Experts available now in Live!

Get 1:1 Help Now