Snippets

How to remove .html, .php, etc (extension) from URL?

To remove the .html extension from your urls, you can use the following code in root/htaccess :

RewriteEngine on

RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]

NOTE: If you want to remove any other extension, for example to remove the .php extension, just replace the html everywhere with php in the code above.

Share

Recent Posts

Redirect non-www to www and HTTP to HTTPS using htaccess

Below snippet shows how to redirect a site from non-www to www (or viceversa) and…

5 years ago

.htaccess file useful snippets

If you get 404 page not found error after installation. In this case your server…

6 years ago

Redirect non-www to www in .htaccess

Below snippet shows how to redirect a site from non-www to www [crayon-662ff30982e8d214117900/] or [crayon-662ff30982e92765030994/]…

6 years ago

Common .htaccess file Redirects

Below shows common redirects using htaccess file. [crayon-662ff30983095939948399/] The CI .htaccess shouldn't be in the…

6 years ago