Want to match optional trailing slash

I’m running 1.6.9 built recently with USE_PCRE=1 on my Raspberry Pi. I want to allow the URLs

http://server.mydomain.com/subdir
-or-
http://server.mydomain.com/subdir/

to match

What I tried was

acl mysubdir_req path_beg /subdir/?

using the ‘?’ PCRE regex for “0 or 1” matching but it doesn’t work.

If I remove the ? it does work as long as I include the trailing slash which is what I expected.

path_beg is not a regex.

Use
acl mysubdir_req path_reg ^/subdir/?

or better yet avoid the regex and just write:
acl mysubdir_req path_beg /subdir/ /subdir

Ah! NOT a regex? Well, I’ll have to watch out for that. Thanks!

Without using regex, if you use the last acl:

acl mysubdir_req path_beg /subdir/ /subdir

It’ll match more than desired, like this example:

/subdir/ - yes
/subdir - yes
/subdir2 - yes
/subdir/subdir/ - yes

Maybe it is better a combination of two acls:

acl mysubdir_req { path /subdir } OR { path_beg /subdir/ }

That resul on:

/subdir/ - yes
/subdir - yes
/subdir2 - not
/subdir/subdir/ - yes

Yes, replace path_beg with path if you want to match the path exactly.