Remove index.html and/or index.php from the URL

Coding web page | Rolands Umbrovskis | February 22, 2010 7:56 pm 857 views | 1 Comment

Inspired by my discussion with Kaspars on his homepage konstruktors.com how to better remove index file. So I’ll post both versions, because they use different methods: with and with out RewriteEngine On.

Here is mine with RewriteEngine On (works on this hosting and both versions of GoDaddy hosting plans example1.com and example1.com/example2.com):


# This will remove index.html AND index.php from URL
RewriteCond %{THE_REQUEST} \/index\.(php|html)\ HTTP [NC]
RewriteRule (.*)index\.(php|html)$ /$1 [R=301,L]

And Kaspar’s method without RewriteEngine On:


RewriteEngine On # remove this, if you have it already
RewriteCond %{REQUEST_URI} index\.html
RewriteRule ^(.*)index\.html$ /$1/ [R=301,L]

Purpose of this is to remove duplicate content from Internet.

[Update on 2010.03.30]

Please keep in mind that some web applications still need index.php file for installation scripts as referrers. So it’s good to keep it in mind and comment these line during installation process if it fails.


# This will remove index.html AND index.php from URL
# RewriteCond %{THE_REQUEST} \/index\.(php|html)\ HTTP [NC]
# RewriteRule (.*)index\.(php|html)$ /$1 [R=301,L]

Related Posts

Removing WWW from URI (or domain) with PHP
Removing WWW from URI (or domain) with PHP

Few weeks ago I wrote how to remove WWW from domain with .htaccess. In some cases or hosting plans it's not possible to view or use .htaccess file...

Final cut for my first WordPress plugin
Final cut for my first WordPress plugin

More than one month ago I published my first WordPress plugin "Draugiem.lv/lapas fan page" for social network in Latvia draugiem.lv (FRYPE.COM)....

Writing first public WordPress Plugin (widget)
Writing first public WordPress Plugin (widget)

Today was first release of  "Draugiem.lv/lapas Fan page" (for non-Latvian draugiem.lv best known as Frype.com) WordPress sidebar widget for FRYPE...

New development blog for WordPress,BuddyPress, WP MU and Web pages
New development blog for WordPress,BuddyPress, WP MU and Web pages

Followed by Latvian web development blog version, here will be my English blog for web, WordPress, BuddyPress and WPMU development.

WordPress theme feature vs. WordPress plugin. What is best choice?
WordPress theme feature vs. WordPress plugin. What is best choice?

As WordPress developer at SimpleMediaCode.com I came to point where I have to decide: make some functions as WordPress theme features or make them...

 
 
draugiem.lv/say SekoMan.lv twitter Digg this! Add to del.icio.us! Stumble this! Add to Techorati! Share on Facebook! Seed Newsvine! Reddit! Add to Yahoo!

Rolands Umbrovskis

Web developer at "Simple Media Code" / Mediabox.lv

Follow Rolands Umbrovskis on Twitter or Facebook

1 Comment »

Atsauces

  1. March 2, 2010 Kā atbrīvoties no index.html un index.php lapas adresē | WordPress freelancer | Mājas lapu un blogu izstrāde : MediaBox

RSS feed for comments on this post. TrackBack URI

Leave a comment

Note: This post is over 6 months old.

 



bt bt bt bt
plugin by DynamicWP
#