Search code examples
regex.htaccesshttp

.htaccess: allow access to directories that begin with the letter "r" using regex


I have a .htaccess file where I want to deny access from all DIR's except the folders in /docs/ that are called r20 or r21, and I will want to add more DIR's in the future where they will start with r. What regex expression can I use? Thanks.

RewriteEngine On

<DirectoryMatch "^/docs/r">
   Order deny,allow
   Deny from all
</DirectoryMatch>

Solution

  • Thanks to @CBroe's suggestion, this works for me.

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/docs/r
    RewriteRule !^/docs - [F]