Solved

Apache Rewrite Rule with Query_String

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

23 Experts available now in Live!

Get 1:1 Help Now