homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

mod_rewrite help - removing filename
how do i remove a filename

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


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)

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


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

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


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


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)

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 index.html from most requests would be not to use links that end with /index.html on any of your pages. Then the only requests that will ever use the index.html 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)

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...

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved