Removing .html and .php extension from url

Discussion in 'Tutorials' started by DarkTheGreat, Nov 18, 2016.

  1. DarkTheGreat

    DarkTheGreat New Member

    Joined:
    Nov 28, 2015
    Messages:
    5
    Likes Received:
    0
    Hello,
    This is a quick tutorial on how to remove the '.php' and '.html' and the end of a url

    Like http://www.mysite.com/index.php would be http://www.mysite.com/index
    This makes it more user friendly for people that dont really know about the .php extentions
    etc..

    First create a new file called '.htaccess' with nothing before or after just .htaccess
    First you need to include this:
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    And this will enable the Rewriting of a file
    Once, that is done just simply add this code to remove .php:
    Code:
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
    And add this code to remove .html:
    Code:
    RewriteRule ^([^\.]+)$ $1.html [NC,L]
    So now instead of adding links like this: http://mysite.com/log_in.php
    You can use this: http://mysite.com/log_in

    Thanks,
    Hoped this helped!

    P.S You cannot use .html & .php at once
     

Share This Page