Forum Moderators: phranque

Message Too Old, No Replies

rewritemap and http cookie question

problem with rewritecond and cookies

         

mellofan

3:59 pm on Mar 8, 2010 (gmt 0)

10+ Year Member



Hi, I'm searching all over the web but cannot find a solution to the following problems.
I want to redirect all requests to /aposerver/dome1 to a login page with php script which should do authentication. If authenticated a rewriterule should proceed. Please note that the php authentication cannot proceed with another page, because dome1 rewrite should be a total different system with a different application webserver.
I did the following:
<virtualhost *>
servername aposerver
rewriteengine on
rewritemap mysession prog:/srv/www/htdocs/login/checkcredentials.php
<Directory /srv/www/htdocs/dome1/*>
rewriteengine on
options +followsymlinks
rewritecond %{HTTP_COOKIE} !auth_name=([^;]+)
rewriterule .* - [L-,R=403]

rewritecond %{HTTP_COOKIE} auth_name=([^;]+)
rewritecond %{mysession:%1} !OK
rewriterule .* - [L,R=403]
</directory>
</virtualhost>

the php script as it's now only returns OK on every entry.
#!/usr/bin/php
<?php
set_time_limit(0); //no timeout
while($input = trim(fgets(STDIN, 1024))){
if ($input){
fputs(STDOUT, "OK");
}

fputs(STDOUT,"\n");
flush(); //send result to stdout, very important. no buffering
}
?>
So if I set the cookie auth_name to some value I should pass. But the result is that I can always see the page, also when the cookie is not available. What is wrong here.

jdMorgan

6:51 am on Mar 10, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's not clear how your set-up works... If you are using a back-end server for auth, it should be set up as a reverse proxy -- you should not be redirecting the client to it, just passing the request from your front-end server to the back-end for authorization.

However your first RewriteRule above is malformed, and should read:

RewriteRule .* - [F]

I'm not sure how that "-" got in the flags, but it doesn't belong there. And [F] is short for [R=403,L].

Jim