Remove file extension, not to be seen by the user

Posted on

Coding Problem :

How would I make the file extension not seen by the user?


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?


asked by anonymous 05.12.2017 / 12:34

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]


  • %{REQUEST_FILENAME} – will check from the directory ROOT + o "arquivo" da url solicitada (want to say that it excludes QueryString)


  • Your site is in /www/ (Directory ROOT of project)
  • The requested url is
  • %{REQUEST_FILENAME} will /www/contato


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

Leave a Reply

Your email address will not be published.