Forum Moderators: phranque

Message Too Old, No Replies

Emulating redirect as replacement to a script

can you guys see it I got it right?

         

phoenix_fly

8:23 pm on Jan 13, 2006 (gmt 0)

10+ Year Member



Hello Jim and all

I have a perl script that does this:

<code>

use CGI; my $q = new CGI;

my $cookie = $q->cookie( -name => "cookie" );

if (! defined $cookie ) {

print $q->redirect( -url => "http://www.mysite.com/cgi-bin/start.htm" );

}else {

print $q->redirect( -url => "http://www.mysite.com/cgi-bin/start2.cgi?$ENV{QUERY_STRING}" );

}

</code>

But as I have to reduce my CPU usage, and it is using a lot of CPU, as it is the start page, I am willing to pass this task to mod_rewrite. Can you please tell me if the mod_rewrite equivalent would be this one below?

<code>
# Ok, the cookie came in, client logged, throw him to the .cgi
RewriteCond %{HTTP_COOKIE} session_id
RewriteCond %{HTTP_HOST} \.mysite\.com [NC]
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^cgi-bin/start\.cgi [mysite.com...] [R=301,L]

# anonymous visitor, throw him to the static cron-generated html
RewriteCond %{HTTP_COOKIE} ^$
RewriteCond %{HTTP_HOST} \.mysite\.com [NC]
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^cgi-bin/start\.cgi [mysite.com...] [R=301,L]

</code>

Thanks a lot

phoenix_fly

jdMorgan

5:07 pm on Jan 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It'd really be better to test your code before posting, as that would answer your question more quickly.

The code looks OK, except that there is no need to 'handle' the query string in any special way. If you delete the RewriteCond that tests the query string, and remove the "?" from the RewriteRule substitution URL, then the query string will be passed through, unmodified, by default.

Jim

phoenix_fly

5:24 pm on Jan 17, 2006 (gmt 0)

10+ Year Member



Thatīs great! Thanks a lot Jim! Iīll go test it then.
Take care
phoenix_fly