5

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 ?

Abu Romaïssae
  • 3,841
  • 5
  • 37
  • 59
ZinebM
  • 109
  • 2
  • 7
  • 1
    did you check this [list](http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html#Mod_Rewrite_Variables) ? – Abu Romaïssae Mar 04 '13 at 11:00
  • 1
    my be this helps http://stackoverflow.com/questions/1200348/how-do-i-make-htaccess-work-on-the-current-directory-and-not-subdirectories – Krishan Gopal Mar 04 '13 at 11:33
  • Apparently, it is impossible to obtain the current directory path in .htacess files via an expression. Just one of a handful of remarkable limitations of using Apache directives in .htaccess files. – David Spector Dec 05 '22 at 12:18

1 Answers1

2

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]
Abu Romaïssae
  • 3,841
  • 5
  • 37
  • 59
Azzeddine
  • 176
  • 2
  • 9