My suggestion is to check if the "file" (being real or "virtual") is only considered in URL after slash ( /
), this would avoid conflicts with files with different names (it is a bit difficult to detail the problem now), should be something like:
RewriteEngine On
# Redireciona
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,NC,L]
# Reescreve
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)(/|)$ $1.php [L]
The (.*)
gets the path and the (/|)
is to "ignore" /
, this will help to access the URL like this:
That would cause this:
-
/pasta/public_html/foo/bar/.php
And this does not exist, if I understand you want /foo/bar
and /foo/bar/
(example urls) to access /foo/bar.php
, the above code should solve, now might not work , try this (ps: I did not have time to test):
RewriteEngine On
# Redireciona
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,NC,L]
# Reescreve
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)([^/]+)(/|)$ $1$2.php [L]
If you have some POST form that sends to .php
, this will fail:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,NC,L]
Because it will conflict POST and redirection, what you can do is a check, something like:
RewriteEngine On
# Redireciona
RewriteCond %{REQUEST_METHOD} !^(PUT|POST)$ [NC] #ignora o POST e PUT
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,NC,L]
# Reescreve
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)(/|)$ $1.php [L]
Still, it's best to tweak your FORM, get .php
, like this:
<form class="m-t" role="form" method="post" action="validaacesso.php">
by
<form class="m-t" role="form" method="post" action="validaacesso">