uri regular expression matching

Hi, for some reason I cannot get a uri to match the following regular expression check.

<If $uri !~'^/dir/\?somename=(.*)'>

NameTrans fn="restart" uri="/shownomatch?uriwas=$uri"

</If>

<Else>

NameTrans fn="restart" uri="/showamatch?value=$1"

</Else>

I can see in the page that is restarted to that it should match by printing out the uriwas parameter.

An example uri that should match but doesn't is /dir/?somename=5f801297-a8f6-42a4-933d-660f2120cd0d

Any thoughts? I've tried a few different valid regular expressions, but cannot get a match.

[746 byte] By [bartmcpa] at [2007-11-27 11:15:21]
# 1

If I add an actual file name to the uri it does match.

(i.e. /dir/index.jsp?somename=blahblahblah)

I tried moving the path check line above the logic, but it did not work.

PathCheck fn="find-index" index-names="index.html,index.htm,home.html,index.jsp,index.php"

Is there a way around this? I can't always be sure of the index file's name .htm|.html|.jsp.

bartmcpa at 2007-7-29 14:12:25 > top of Java-index,Web & Directory Servers,Web Servers...
# 2

I haven't tried mangling this, but I'd bet money it's 'cause you're matching on the query string (the bit after the ?) Try using

$url

instead of

$uri

or maybe try somethign like this (I haven't tried it, don't know if it'll work):

<If $uri !~ '^/dir/'

and $query !~ 'somename=(.*)'>

JoeMcCabea at 2007-7-29 14:12:25 > top of Java-index,Web & Directory Servers,Web Servers...
# 3

Try something like this

<If $uri !~ '^/shownomatch' and $uri !~ '^/showamatch' >

<If $uri =~ '^/dir/' and $query =~ 'somename=(.*)'>

NameTrans fn="restart" uri="/showamatch?value=$1"

</If>

<Else>

NameTrans fn="restart" uri="/shownomatch?uriwas=$uri"

</Else>

</If>

1.- The external <if> I put to ensure no infite loop going into the else :D

2.- I always prefer <if> to test for positives :D

nseguraa at 2007-7-29 14:12:25 > top of Java-index,Web & Directory Servers,Web Servers...
# 4

bartmcp: Is the intent to have *all* requests redirected either to showamatch or shownomatch?

nsegura's conditions for preventing an infinite loop are not right as they will prevent the server from getting access to a web application's web.xml file etc. Instead I think you want something like this

<If not restarted and not internal>

<If $uri =~ '^/dir/' and $query =~ 'somename=(.*)'>

NameTrans.....

</If>

<Else>

NameTrans.....

</Else>

</If>

And you should put these directives above the

NameTrans fn="ntrans-j2ee" name="j2ee"

line in obj.conf.

Arvind_Srinivasana at 2007-7-29 14:12:25 > top of Java-index,Web & Directory Servers,Web Servers...
# 5

Thank you all for the help.

My main goal was to provide verification that a user has logged in and has the proper authority to access a directory/resource. What I believe I now have is a check to verify that the user has a required cookie and that the value in the cookie matches the parameter in $query.

Below is what I now have in the server's obj.conf file. Let me know if you think there is something that I am missing.

<If $uri =~ '^/ValidationApp/*'>

<Client security="false">

NameTrans fn="redirect" url-prefix="https://server.domain.edu"

</Client>

</If>

<If $uri !~ '^/ValidationApp/*'>

<Client security="true">

NameTrans fn="redirect" url-prefix="http://server.domain.edu"

</Client>

</If>

<If $uri =~ "/SomeDir/*">

<If not defined $query or not defined $cookie{"$(lookup('cookiemap.conf','/SomeDir'))"} or $query !~ 'uuid=(.*)' or $& ^ $cookie{"$(lookup('cookiemap.conf','/SomeDir'))"}>

NameTrans fn="restart" uri="/ValidationApp/CookieCheckServlet?loc=$uri&uid=$(uuid())&ReqInfo=$(lookup('cookiemap.conf','/SomeDir'))"

</If>

</If>

<If $uri =~ "/AnotherDir/*">

<If not defined $query or not defined $cookie{"$(lookup('cookiemap.conf','/AnotherDir'))"} or $query !~ 'uuid=(.*)' or $& ^ $cookie{"$(lookup('cookiemap.conf','/AnotherDir'))"}>

NameTrans fn="restart" uri="/ValidationApp/CookieCheckServlet?loc=$uri&uid=$(uuid())&ReqInfo=$(lookup('cookiemap.conf','/AnotherDir'))"

</If>

</If>

The servlet used in the restart checks to see if the required cookie exists (ReqInfo) and if the uuid value (uid) is set in the session. If so it forwards to the uri (loc). If not it forwards to a login form the checks the user ID/password. It adds the uid to the session, creates the cookie, and forwards back to the requested uri.

The Client security checks are down to make sure the user uses HTTPS when entering their user ID/Password.

bartmcpa at 2007-7-29 14:12:25 > top of Java-index,Web & Directory Servers,Web Servers...