Java, Python, Database, Flutter, Matlap, Micorcontroller, Tutorials, Swing Framework

Hancie e-Learning Studio

Learn Java, Learn HTML, CSS, PHP, Javascript, Python Tutorials || Download program source codes || Java Project and Source code available here || All types error troubleshooting tips available here

How to remove .php , .html extensions from .htaccess?

 


What is an .htaccess file

A text editor like Notepad or TextEdit is used to generate an.htaccess file, which is a straightforward ASCII file. The file informs the server of the specific configuration adjustments that need be made for each directory.

.htaccess files have an impact on the directory they are put in and all of its descendants (sub-directories). One.htaccess file, for instance, may effect yoursite.com/content/, yoursite.com/content/images/, and so on if it is present in the root directory of your website.

It's crucial to keep in mind that this can be done without. Place a new.htaccess file within the directory you don't want to be impacted by the modifications and delete the desired command(s) from the new file if you don't want certain.htaccess commands to touch that directory.

Features

With an .htaccess file you can:

  • Send the user to another page
  • Protect a specific directory with a password
  • User blocking using IP
  • preventing your photographs from being hot-linked
  • Change URLs
  • Your own customized error documents

Removing Extensions

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:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

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 change the last line from the code above, to match the filename:

RewriteRule ^([^\.]+)$ $1.html [NC,L]

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

<a href="http://whatever.com/wallpaper" title="wallpaper">wallpaper</a>

Adding a trailing slash at the end

example: yoursite.com/page/

Ignore the first snippet and insert the code below. The first four lines deal with the removal of the extension and the following, with the addition of the trailing slash and redirecting.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]














Welcome all to Hancie e-learning studio
Friends,
I have brought an e-learning platform for you from where you can teach internet, website, programming language, error troubleshooting, etc. Blogger, WordPress templates, themes are available for free on this website, which are not charged for downloading, so that you can earn money by blogging using such templates and this is not a difficult task and this You can do it now. You keep uploading new posts by us and keep taking advantage of this website. The aim of which is to spread the knowledge related to internet, career, web designing and technology to the people and contribute to the development of the country.