remove html from url

How to Remove .html from URL in Apache/WordPress

By default, Apache adds .html to URL for HTML files. Here’s how to remove .html from URL in Apache. You can use these steps to remove .html from URL in WordPress, Magento, Drupal, Joomla and other CMS systems. You can also use it to remove index.html from URLs.


Remove .php extension from URL

Before proceeding further, you need to enable mod_rewrite in Apache web server. Here are the steps to enable mod_rewrite (.htaccess) in Apache web server.

1. Open htaccess file

Open terminal and run the following command to open .htaccess file. Please change the file path to .htaccess file as per your requirement.

$ sudo vi /var/www/html/.htaccess

Bonus Read : How to Remove .php from URL


2. Remove .html extension from URL

Add the following lines to redirect all URLs with .html extension to URLs without file extension.

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

In the above code, the first line checks that the request is a URL and not a directory. The second line redirect matching URLs with .html extension to those without file extension. The last line redirects matching requests to URLs without html file extension.

Bonus Read : How to Disable mod_security in Apache


3. Restart Apache web server

Restart Apache server with following command

$ sudo systemctl restart httpd

Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!