Forum Moderators: phranque

Message Too Old, No Replies

Redirection Problems

         

tstorms

5:35 am on Oct 9, 2007 (gmt 0)

10+ Year Member



Hi
I've been playing around with the mod_rewrite module for the last couple of days but cant seem to be getting the right result.

I'm basically trying to perform the following scenario:
> Have restricted web page
> Check if user is authorised to view page (check.pl)
>> If successful, show page to user (original request)
>> If failed, show error page to user (intranet-deny.cgi)

I've played around with lots of alternatives to try and make this work. I have come up with the below. The way I read the following is:

> If url contains the keyword "Restricted"
> Parse url through to checkAuth
--- check.pl checks if logged in user has 'READ' access
--- if they do redirect them back to the same url
--- if they dont, redirect them to error page

Appreciate your input to try and get this working.

= httpd.conf ========================

RewriteMap checkAuth prg:/usr/app/scripts/check.pl

RewriteCond %{REQUEST_URI} /Restricted\+.*$
RewriteRule ^(.*)$ ${checkAuth:%{$1}} [L]

= check.pl ==========================

#!/usr/bin/perl
require "../web-common.pl";

$¦ = 1;
while (<STDIN>) {
if (!($userauth->authUser($_[0],'READ')) {
#return "Not Authorised";
return "https://ilisten/intranet-deny.cgi\n";
}
else {
#return "Authorised";
return "https://ilisten/$_\n";
}
}

[edited by: jdMorgan at 12:38 pm (utc) on Oct. 9, 2007]
[edit reason] Disabled smilies in code [/edit]

jdMorgan

12:54 pm on Oct 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Commenting on your rewritemap rule only, you don't really need a separate RewriteCond, as the same thing can be accomplished in the rule itself. Also, the "$1" back-reference syntax looked strange. I'd suggest:

RewriteRule (.*Restricted.*) ${checkAuth:$1} [L]

As for your main question, it would be helpful to know the following:
1) How did you test -- What URL-paths did you try?
2) What were the results? (Server error, 404, error log entries)
3) How did these results differ from your expectations?

Also, remember to completely flush your browser cache after any change to the code on your server.

Jim