Coding Problem :
How would I make the file extension not seen by the user?
Example
As soon as the user finishes the registration, it will be directed to the confirmacao.php
page, but would like the .php
extension not to be visible, only confirmacao/
. I understand that this is Url friendly and can be done by .htaccess
, but how can I apply on all pages?
-
contato.php
= >contato/
-
cadastro.php
= >cadastro/
- etc.
Is this possible? Or would I have to create a directory for each page?
Answer :
Answer 1 :
In my .htaccess I use this code snippet to remove .php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*.php$ %{REQUEST_FILENAME}.php [QSA,L]
Explanation
-
%{REQUEST_FILENAME}
– will check from the directoryROOT
+o "arquivo" da url solicitada
(want to say that it excludes QueryString)
Example
- Your site is in
/www/
(DirectoryROOT
of project) - The requested url is
domain.com/contato?name=Guilherme
-
%{REQUEST_FILENAME}
will/www/contato
Resuming
- In the
RewriteCond %{REQUEST_FILENAME}.php -f
rule it says: Take this path (/www/contato
) add.php
and check that it is a file-f
(file) - True case apply the rule below
-
!.*.php$ %{REQUEST_FILENAME}.php
– If you do not have.php
at the end, add, holding the QueryString[QSA]
settings.
Even though the rule is saying add .php
in the end this is an internal configuration, for PHP to identify the file, the user does not even know that this occurs.
Answer 2 :
Answer 3 :
Answer 4 :
Answer 5 :
Answer 6 :
Answer 7 :
Answer 8 :
Answer 9 :