Remove file extension, not to be seen by the user

6

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?

    
asked by anonymous 05.12.2017 / 12:34

1 answer

4

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 directory ROOT + o "arquivo" da url solicitada (want to say that it excludes QueryString)

Example

  • Your site is in /www/ (Directory ROOT 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.

    
05.12.2017 / 12:39