Point to different directory in .htaccess

1

Does anyone know if there is any way to RewriteRule , be able to point to a path, which is in folders behind where I have my htaccess .

For example

RewriteRule ^cena.js$ ../../../pasta/pasta2/file.php [L]

This code does not work since .htaccess does not like that path.

    
asked by anonymous 15.02.2016 / 13:51

2 answers

2

Using ../../../ will not work at all, since .htaccess works from the "Base" directory or that you defined as "Base".

By default the Base is the location where the .htaccess is located and in case it can help you to use RewriteBase to configure the new "Base", note that the path defined in it must be absolute, for example , assuming that pasta/pasta2 is in the apache root, but the .htaccess is in the /etc/www/projeto1/admin/dashboard/pasta/pasta2 folder, then you should do this:

RewriteEngine On

RewriteBase /
RewriteRule ^cena.js$ pasta/pasta2/file.php [L]
The RewriteBase / will lead to the root of Apache, in the /etc/www case, note that all mod_rewrite rules will always start from /etc/www/ , so you will always work from the new "Base."

    
15.02.2016 / 14:24
1

A logical reason for not working, if the path is correct, is the file being outside the public folder defined at DocumentRoot .

Example, if the DocumentRoot of the site is in /site/public/html/ , you will not be able to access a file above this directory by the rewrite rule of htaccess , example: /site/public/arquivo.php . >

It is accessible by PHP using include() , for example, and obviously it must also have the access permissions assigned to Apache and PHP. These settings are set by the Operating System .

    
15.02.2016 / 14:12