Remove index.html and index.php from your URLs

axe.jpgIn additional to having a love hate relationship with my Youtube Video Downloader, I also have a love hate relationship with the statistics that I see on this site.  While I don’t use the index.html bit in the urls within Movable Type, some folks use it when they link to me.  This splits up page views like crazy.  Makes writing up a Most Read Posts post a pain since I have to sit there with a calculator and work out the numbers. (Hmm, I haven’t done one of those in quite a while.)

So anyway, I needed to work out a method of removing the ‘index.html’ bit from the url.  I came up with the following and added it to my htaccess file:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} \/index.html\ HTTP [NC]
RewriteRule (.*)index.html$ /$1 [R=301,L]

Now the first two lines may already be in your site’s .htaccess file.  If you’re using WordPress, the second line definitely is as it’s required to get pretty permilinks to work.  The third line checks to see if the ‘index.html’ bit is found within the url and the fourth lines removes it but leaves everything else there.

If you’re using WordPress, since you don’t use ‘index.html’ files but ‘index.php’ you need to use the following instead:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} \/index.php\ HTTP [NC]
RewriteRule (.*)index.php$ /$1 [R=301,L]

Does it work for you?  Here’s a pair of links to a previous post about Mac Wallpapers.  The first link has the index.html bit and while the second does not.  Give it a try.

Mac Desktop Wallpaper
Mac Desktop Wallpaper

3 thoughts on “Remove index.html and index.php from your URLs

  1. Remove the www from URLs

    Awhile back, I did a quick tutorial on how to remove the index.html and index.php files from your urls.  I did it because having both in my stats was driving me nuts and causing dupe urls within Google as well. …

Leave a Reply to Sagar Cancel reply

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