Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 985
ZinebM Avatar asked Nov 04 '22 03:11

ZinebM


1 Answers

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]
like image 52
Azzeddine Avatar answered Nov 09 '22 12:11

Azzeddine