regex.htaccessapache2global-variables

How to refer to the current directory in htaccess


I need to get dynamically the current directory in which my .htaccess file is located. Is that possible ? (A variable maybe ?).

Something like : %{SCRIPT_FILENAME}

Thank you in advance.

EDIT : If with regular expressions ? how should it look like ?


Solution

  • Actually Apache still does not have pathinfo($,PATHINFO_DIRNAME) function like PHP does.

    So on, there have been solutions based on the usage of %{REQUEST_URI}, like this example:

      RewriteRule ^(.+)/$ /path-dirname/$1 [R=301,L]
    

    Regarding your issue, this may work for you:

      RewriteCond %{REQUEST_URI} ^(.+)/$
      RewriteRule ^.+/$ %1 [R=301,L]