19
As an example, using the variable SCRIPT_FILENAME
we can get the requested file, but for this problem we want to get the directory where the file is .htaccess
:
# Rewrite the url
<IfModule mod_rewrite.c>
RewriteEngine On
#DirectorySlash Off
RewriteBase /
# Redirect when the target isn't an existent file or directory
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^ /www/index.php [L]
</IfModule>
The idea is to replace the www
by a variable so that when changing the file .htaccess
location it is not necessary to edit it to change the reference.
In practical terms, and for this specific case, the code above is used inside a folder that is at the root of the housing, ie within the public_html
.
The following rule:
RewriteRule ^ /www/index.php [L]
can be:
RewriteRule ^ /www2/index.php [L]
or
RewriteRule ^ /bubu/index.php [L]
Question
Is there any way to reference the directory where the file .htaccess
is, even if limited to the specific scenario indicated here?
Note: In the list of variables available there seems to be nothing pre-made :(
– Zuul
I don’t bro much of . htaccess, my do is push everything pro index.php and turn it (:p), but what that %{PATH_INFO} would return?
– Bruno Augusto
@Brunoaugusto Portion of the path in use that comes after the place where the
.htaccess
if memory serves me well.– Zuul
@Brunoaugusto take a test in this layout:
http://seusite/teste.php/pasta/pasta
(no folders need to exist, the important thing is that the.php test contains a<?php phpinfo(); ?>
for you to see some new variables. Add this with a little imagination (setting the server to serve files with no extension as PHP) and at certain times until the.htaccess
you’ll be able to stop using.– Bacco
Maybe some other time. Today there are two lines just to direct the flow pro index.php (which is my bootstrap) and my Frontcontroller does the rest. : D
– Bruno Augusto
@Zuul little worked with apache settings, but in linux environments and even in windows use the
./index.php
would mean that the file would be in the application’s current directory, but I don’t know if it will work with apache.– Pablo Tondolo de Vargas
Check out this http://stackoverflow.com/questions/21027343/let-htaccess-rewriterule-redirect-to-a-script-in-current-dir-instead-of-an-e
– Renato Tavares
Try using the variable
{ENV:BASE}
.
 
 Reference:
 http://stackoverflow.com/questions/21027343/let-htaccess-rewriterule-redirect-to-a-script-in-current-dir-instead-of-an-e– Douglas de Souza
@Zuul And if we rewrite the
index.php
, without the/
at first?– Mariano