Point to different directory in . htaccess

Asked

Viewed 953 times

1

Does anyone know if there is any way with the RewriteRule, can point to a path, which is in folders behind where I have mine htaccess.

For example

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

This code does not work since .htaccess doesn’t like that way.

2 answers

2


Use ../../../ will not work at all because . htaccess works from the "Base" directory or you have defined as "Base".

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

RewriteEngine On

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

The RewriteBase / will take the root of Apache in case /etc/www, note that all rules of mod_rewrite will always start from /etc/www/, then you will always run from the new "Base".

1

A logical reason for not working if the path is correct is that the file is outside the public folder defined in Documentroot.

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

It is accessible by PHP using include(), for example, and obviously you should also have the access permissions given to Apache and PHP. Such settings are defined by Operating System.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.