remove php

How to Remove PHP Extension From URL


How to Remove .php Extension From URL

In this post, we will show you how to remove the .php and .html extension from the URL using htaccess file. Having file extensions like .php, .html at the end of the URL doesn’t hurt SEO, but removing them will make the URL more readable. CMS like WordPress hides file extensions in URLs which makes it user-friendly. You can do the same for other websites (even those built with core PHP) with the help of the .htaccess file.

A .htaccess file is an ASCII file that allows you to set the configuration of the Apache server. With Access Files, you can rewrite URIs, block IPs, restrict access to directories with passwords, etc. Here we will see how to remove/hide file extension from URL with htaccess file.

Remove .php Extension From URL

To remove the .php extension from the URL, we have given you a code below, copy it and paste it in your .htaccess file, if there is no .htaccess file then create a new file named .htaccess

Example:-

Create a .htaccess New File.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php

Note:- If you are working in online Cpanel then the .htaccess file will paste this code on it If you are working it in offline localhost then you have to create a new .htaccess file.

Remove .html Extension From URL

To remove the .html extension from the URL, we have given you a code below, copy and paste it in your .htaccess file, if there is no .htaccess file, then create a new file named .htaccess.

Example:-

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html

Note:- To remove the .html extension from the URL, we have given you a code below, a online will work in server like localhost to, direct location will not work.

Sometimes you would like to have user-friendly URLs on your site. For example, instead of https://www.example.com/index.html, you’ll want to have https://www.example.com/index. The second URL looks much better. Also, from an SEO point of view, it is better not to use a file extension.

How to Remove .php, .html extension from the URL in cPanel

Steps to remove file extension are given below

  1. Log in to your cPanel account.
  2. Go to File Manager – File Section
  3. In File Manager, go to the Settings button at the top right corner.
  4. On the Preferences window that appears, check the Show hidden files (dotfiles) option. Click on the Save button to apply the settings.
  5. Now navigate to the .htaccess file. If the file does not exist, you must create it.
  6. Click on the Edit button from the File Manager top menu.
  7. Add the below lines to the .htaccess file. Click the Save Changes button and then click the Close button.


RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php



RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html



Related Posts

Leave a Reply

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