Forum Moderators: phranque
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:
<code>
RewriteRule ^index\.html?$ / [R=301,L]
</code>
I'm kinda new to mod_rewtite and I keep crashing the server. Thanks for any input...
Doug
[edited by: florida_guy at 4:34 pm (utc) on Jan. 16, 2003]
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.
HTH,
Jim
<edited>typo</edit>
[edited by: jdMorgan at 5:24 pm (utc) on Jan. 16, 2003]
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]
Andreas
<edit>Dave and Jim were faster ;). Go with their advice. Mine is basically the same.</edit>
<edit2>typo</edit2>
[edited by: andreasfriedrich at 6:35 pm (utc) on Jan. 16, 2003]
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]
AFTER
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...