Forum Moderators: phranque

Message Too Old, No Replies

Rewriting based on query string

         

Big_Cheese

10:38 pm on Jun 28, 2004 (gmt 0)

10+ Year Member



Hi there. I've looked all over the place and tried a number of combinations but just can't get this figured out.

I'm trying to redirect someone to an external domain if a script is being called on my server with a specific name/value pair.

For example, if cmd=test is anywhere in a query string for script.cgi (www.website.com/script.cgi?cmd=test), I want to send the person to www.siteb.com.

Thanks!

jdMorgan

10:54 pm on Jun 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Big_Cheese,

Welcome to WebmasterWorld [webmasterworld.com]!

Please post your code, and we'll try to help, but in accordance with our charter [webmasterworld.com], we can't write it for you.

You can also try this search [google.com] for some ideas.

Jim

Big_Cheese

11:14 pm on Jun 28, 2004 (gmt 0)

10+ Year Member



Thanks for the welcome jd.

I tried that search but still couldn't find anything :(

Here are a couple different things I tried but to no avail:

RewriteCond %{QUERY_STRING} ^cmd=test$
RewriteRule ^script\.cgi$ [siteb.com...] [R,L]

RewriteCond %{QUERY_STRING} script\.cgi\?(.*)?cmd=test
RewriteRule .* [siteb.com...] [R,L]

Thanks

Big_Cheese

11:24 pm on Jun 28, 2004 (gmt 0)

10+ Year Member



Tried this as well...

rewriteCond %{query_string} cmd=test
rewriterule ^script.cgi$ [siteb.com...] [R,L]

jdMorgan

11:34 pm on Jun 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The first snippet you posted was close, except for the start and end anchors on the querystring pattern.

This code should work if placed in the .htaccess file in your web root directory:


RewriteCond %{QUERY_STRING} cmd=test
RewriteRule ^script\.cgi$ http://www.siteb.com [R=301,L]

I'm assuming that you already have

Options +FollowSymLinks
RewriteEngine on

ahead of your code.

For use in httpd.conf, change the rule to read:


RewriteRule [b]^/s[/b]cript\.cgi$ http://www.siteb.com [R=301,L]

Also, what happens when you request "/script.cgi?cmd=test"? Do you get an error in your log file, does the browser go into an endless redirect loop, or what?

Jim

Big_Cheese

11:50 pm on Jun 28, 2004 (gmt 0)

10+ Year Member



Got it working. Now I just need to get rid of the query string on the end but I'm sure I'll be able to figure that one out.

Thanks for the help.

jdMorgan

11:58 pm on Jun 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just add a "?" to the end of the substitution (new) URL.