Equivalent to PHP dirname (__ FILE__) in Apache rewrite syntax?

Images are served from a folder outside the Apache public folder, and no aliases are needed.

What is the if existing keyword to get a real htaccess path that contains rewrite rules?

# /website1.com/public/prod/ --> index.php & .htaccess # /website1.com/assets/images/ RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^images/(.*)$ REALPATH/../../assets/images/$1 [L] # REALPATH doesn't work of course # not wanted : # RewriteRule ^images/(.*)$ /website1.com/public/prod/assets/images/$1 [L] 
+4
source share
1 answer

You cannot access files outside the .htaccess directory, even using the absolute path. The solution may be to make a symbolic link in the current folder that points to your image directory, and then specify your .htaccess rule for this file.

Your rule should look like this:

 RewriteRule ^images/(.*)$ /assets/images/$1 [L] #this is relative to your .htaccess file 
+1
source

Source: https://habr.com/ru/post/1389319/


All Articles