Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

mod_rewrite help - removing filename

how do i remove a filename



4:30 pm on Jan 16, 2003 (gmt 0)

10+ Year Member


I'm trying to remove index.html from any request.

So, if the request is for '/index.html' needs to be changed to just '/'

I've tried:
RewriteRule ^index\.html?$ / [R=301,L]

I'm kinda new to mod_rewtite and I keep crashing the server. Thanks for any input...


[edited by: florida_guy at 4:34 pm (utc) on Jan. 16, 2003]


4:33 pm on Jan 16, 2003 (gmt 0)

10+ Year Member

Could this be done as a redirect in the htaccess? I'm confused...


5:09 pm on Jan 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

This Intro to Redirects [webmasterworld.com] will help get you started. Welcome to WebmasterWorld! :)


5:17 pm on Jan 16, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member


Welcome to WebmasterWorld [webmasterworld.com]!

There's an interaction here between mod_rewrite and mod_dir. See the online docs for mod_dir at http://httpd.apache.org/ [httpd.apache.org].

You need an intermediate step - rename your index.html to index.htm (for example).
mod_rewrite index.html to "/" with a 301 redirect.
let mod_dir rewrite the request for "/" to index.htm silently.

The above is just a quick outline, but it will allow you to get rid of "index.html" in the URL shown by search engines for your site home page. mod_dir must be set up correctly for this to work.



[edited by: jdMorgan at 5:24 pm (utc) on Jan. 16, 2003]


5:21 pm on Jan 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Welcome to WebmasterWorld [webmasterworld.com] florida_guy.

Be sure to read Marcia`s WebmasterWorld Welcome and Guide to the Basics [webmasterworld.com] post.

The easiest way to remove

from most requests would be not to use links that end with
on any of your pages. Then the only requests that will ever use the
are the ones manually entered by people who just hope that that will be the default filename.

To catch those cases use

RewriteRule (.*)/index\.html?$ $1/ [R,L]
in you top level .htaccess file or better yet httpd.conf (if you have access).

Your rule would always rewrite the URI to the domain root.

DaveAtIFG wrote an excellent tutorial on mod_alias and mod_rewrite which might be helpful for future reference: An Introduction to Redirecting URLs on an Apache Server [webmasterworld.com]


<edit>Dave and Jim were faster ;). Go with their advice. Mine is basically the same.</edit>


[edited by: andreasfriedrich at 6:35 pm (utc) on Jan. 16, 2003]


6:02 pm on Jan 16, 2003 (gmt 0)

10+ Year Member

Thanks everyone for your input.

It's working properly now. I was close to getting it. Thanks andreasfriedrich for the code.

I had to make sure I put:
RewriteRule (.*)/index\.html?$ $1/ [R,L]


RewriteBase /
RewriteRule ^(.*)\.html$ $1 [C,E=WasHTML:yes]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [S=1]
RewriteCond %{ENV:WasHTML} ^yes$
RewriteRule ^(.*)$ $1.html

Which allows a .php file to be called with .html

When I put it after, I got funky results...


Featured Threads

Hot Threads This Week

Hot Threads This Month