How to make url friendly with .htaccess

2

Good morning ... I have been researching this topic but I can not find anything to help me, and I want to avoid that the extensions of my file are shown in the URL (eg contacto.php) What should my htaccess file take to be shown /?

This is the code I have:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteRule ^(.*)$ contacto.php [QSA,L]
</IfModule>
    
asked by jose marquez 18.04.2018 в 00:17
source

1 answer

3

It is enough that your htaccess , contain the following and that you keep it in the root folder of your project so that it works

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>
  

The only thing we have done is to declare that after the point look   any file with extension .php and make its use optional; that is to say   upload the file regardless of whether you put the full name with   everything and url or just the name of the file.

That is, it should work under the following scenarios

hola.php //funcionará

hola //debe funcionar
    
answered by 18.04.2018 / 00:31
source