Hi, I'm configuring my .htaccess
website to put my website into production and the thing is that I don't fully understand it or I don't get along very well with this file and it gives me problems.
I have the following directory structure:
index.php
login.php
.htaccess
includes/
└ panel.php
└ etc..
I .htaccess
have it configured right now like so:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]
</IfModule>
As much index.php
as login.php
they work correctly, since it hides the extension from me .php
as I want.
The problem comes when I log in and it sends me to panel.php
, it shows me the address like this: www.miweb.com/includes/panel , and I don't want it to show me the '/includes/' directory .
How could be the rule that I should configure or where can I have the problem in the current configuration of the file?
Thanks in advance.
You have not asked him to take you to the panel without showing includes. It would have to be something like this:
This would make "www.myweb.com/panel" display "www.myweb.com/includes/panel.php".
What you need to do is break the redirect rules into different steps:
Each step checks for the existence of the substitution before doing it, to make sure that the target PHP script exists.
The first step checks if a file or directory with the requested name exists and in that case nothing is done (the
-
delRewriteRule
).The second step (which will only be executed if the first one fails) checks if the URL we are requesting exists by adding
.php
.The third and last step (which will only be executed if the previous two are not met) checks the existence of the URL in the subdirectory by
includes
adding the extension.php
.You'll have to repeat the last step as many times as you want to hide subdirectories, but keep in mind that only the first match will work.
That is: if you have one file
hola.php
and anotherincludes/hola.php
only the first one will be served and the second one will be masked. The only way to access it will be throughincludes/hola
(match in the second step) orincludes/hola.php
(match in the first step).