Forum Moderators: phranque
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
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