HoganHost blog

[email protected]

How to remove .php, .html extension from URL using htaccess

What is extension in URL?

Extension simply means the type of file.
Extension is added at after the end of file name  and it helps to identify us on which computer language it is written on.

For example, index.php, index.html as we are only talking about html and php.

In the year 2020, you probably want to have a SEO friendly website link and also which easy to remember.
Extensions like .html, .php can create mess sometimes and show your visitors 404 error page if they forget to add .html or .php at the end of the URL.
It might look good when you get visitor directly on your website but its hard for visitors to remember links with extensions.

We got a few question asking how to remove .php, .html extension from URL using .htaccess.
We have made it very simple for you and you can remove it easily.

Steps to remove file extension from URL:

If you are using Control Panel (cPanel, DirectAdmin, Plesk, etc)

1) Login into Control Panel.
2) Go to file manager
3) Settings and check on “show hidden files(dotted)” (Skip this step if you are not using cPanel)
4) Edit .htaccess and enter the code mentioned below depending upon your file extension
5) Save the file and you have successfully removed extension from URL.

If you are using FTP.

1) Open FTP client (filezilla or any other)
2) Login into FTP using FTP details.
3) Locate to root directory (normally public_html)
4) Download .htacess file if present and open in text editor (eg notepad++)
5) Add the below code depending upon the extension you want to remove.
6) Save file and upload it on server. (It will show “replace” option if you have .htaccess file already)
7) Done.

If you are using SSH.

1) Connect to your server via ssh (using putty or any other ssh client)
2) Navigate to public_html of your domain.
3) “nano .htaccess” to edit file using file editor.
4) Paste the code and press “Ctrl + C”
5) Open to save will show, click “y” and press enter.
6) Done

Remove .php extension from URL

The below code will remove .php extension from the end of file.
For example, https://hostathash.com/blog/conact.php will become https://hostathash.com/blog/contact

#Remove .php extension
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

Remove .html extension from URL

The below code will remove .html extension from the end of file.
For example, https://hostathash.com/blog/conact.html will become https://hostathash.com/blog/conact

#Remove .html extension
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html [NC,L]

Once you have added the code in your .htaccess, your extension will be remove and your website will be SEO friendly and also it will be easy for users to remember links.

4 thoughts on “How to remove .php, .html extension from URL using htaccess”

  1. I just would like to give you a huge thumbs up for the great information you have got here on this
    post. I will be coming back to your website for more
    soon.

Leave a Comment

Your email address will not be published. Required fields are marked *