How to reference the current board

Asked

Viewed 234 times

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 :(

  • 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?

  • @Brunoaugusto Portion of the path in use that comes after the place where the .htaccess if memory serves me well.

  • @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.

  • 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

  • @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.

  • Check out this http://stackoverflow.com/questions/21027343/let-htaccess-rewriterule-redirect-to-a-script-in-current-dir-instead-of-an-e

  • Try using the variable {ENV:BASE}.&#xD; &#xD; Reference:&#xD; http://stackoverflow.com/questions/21027343/let-htaccess-rewriterule-redirect-to-a-script-in-current-dir-instead-of-an-e

  • @Zuul And if we rewrite the index.php, without the / at first?

Show 4 more comments

2 answers

1

On UNIX (Linux, BSD, etc) systems you use ./ to refer to the current directory.

1

You can use regex inside . htaccess, which would look something like this:

RewriteRule ^ (\.+)?\/index.php [L]

In the expression I am defining that there can be anything in any quantity or not before the /index.php.

Browser other questions tagged

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