Remove Php Html Extensions With Htaccess

Remove Php Html Extensions With Htaccess

PHP, TUTORIALS

Remove Php Html Extensions With Htaccess




In this lesson we are gonna learn how to remove Php Html Extensions With Htaccess for some security reasons. Here we use the well known technology called .htaccess, a file which is used to redirect the users from one directory to another or files.
The .htaccess file is a file which is mostly used in all the websites which are construct by PHP and some other technologies. Mainly in frameworks like Laravel, CodeIgniter, Zend and etc.
How To Remove Php Html Extensions With Htaccess – What is an .htaccess file
The .htaccess file is an simple ASCII file that you create with a text editor like Notepad or Sublime Text. It provides a way to make configuration changes on a directory basis.

Please note that .htaccess is the file’s extension. It isn’t file.htaccess, it is simply .htaccess.

The .htaccess files will affect the entire directory and the sub folders on the directory. For example if there is one .htaccess file located in the projects root directory of mysite.com, it would affect mysite.com/uploads/, mysite.com/uploads/CSS, etc.
One of the important thing to remember when we wants to create a changes in the particular folder then we have to make a new .htaccess file on it and then make the changes on the single file itself. And then removing the specific commands in the new .htaccess file.
Features – Remove Php Html Extensions With Htaccess
With an .htaccess file you can:
Redirect the user to different page
Password protect a specific directory
Block users by IP
Preventing hot linking of your images
Rewrite URIs
Specify your own Error Documents




Removing Extensions – Remove Php Html Extensions With Htaccess
To remove the .php extension from a PHP file for example yoursite.com/wallpaper.php to yoursite.com/wallpaper you have to add the following code inside the .htaccess file:

If you want to remove the .html extension from a html file for example yoursite.com/wallpaper.html to yoursite.com/wallpaper you simply have to alter the last line from the code above to match the filename:

That’s it! You can now link pages inside the HTML document without needing to add the extension of the page. For example:

One of the trickiest part in this .htaccess file is adding the trailing slash at the end.

The first four lines are used to remove the .php and the .html extensions. Here we don’t remove the both extensions, but you can just remove by change the extensions.
In this lesson we also add these canonical a canonical meta tag in your HTML head.

Leave a Reply