Remove or edit .php or .html from URL

by John H
4 minutes

If you are using a web server running Apache you can easily remove extensions from the url by using the Rewrite command inside of your .htaccess file.  What this allows you to do is change the URL for the asset that is being requested.  You may want to do this for a few reasons -

  1. Hide the file names.
  2. Clean up your URLs
  3. Hide the Serving Language

Removing .php

This would change http://www.example.com/index.php to http://www.example.com/index

  1. Make (or edit) a .htaccess file in the directory of the site you want to hide the .php
  2. Paste this code RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L]

Removing .html

This would change http://www.example.com/index.html to http://www.example.com/index

  1. Make (or edit) a .htaccess file in the directory of the site you want to hide the .php
  2. Paste this code RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.html [NC,L]

Change .php to .html

This would change http://www.example.com/index.php to http://www.example.com/index.html

  1. Make (or edit) a .htaccess file in the directory of the site you want to hide the .php
  2. Paste this code RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+).html$ $1.php [NC,L]

Change .html to .php

This would change http://www.example.com/index.html to http://www.example.com/index.php

  1. Make (or edit) a .htaccess file in the directory of the site you want to hide the .php
  2. Paste this code RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+).php$ $1.html [NC,L]

Change .php to .butt

This would change http://www.example.com/index.php to http://www.example.com/index.butt

  1. Make (or edit) a .htaccess file in the directory of the site you want to hide the .php
  2. Paste this code RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+).butt$ $1.php [NC,L]

Another great resource http://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

Related Articles

Move Wordpress from folder to root domain

When you start a wordpress blog you might want to set it up in a folder called blog - or...

John H John H
~1 minute

Laravel Save Form Post

php artisan make:migration tasks in database / migrations / create tasks table - paste in up() ...

John H John H
~1 minute

Ajax JSON obj to HTML template Using Vue JS

I wanted to take a simple results set from a database using php, return that result set back as a...

John H John H
6 minutes