Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Makosuke

macrumors 604
Original poster
Aug 15, 2001
6,802
1,523
The Cool Part of CA, USA
I've got what seems to be a trivial thing to do but I can't seem to get it working right. What I want to do is transparently remap "index.html" (only) to "index.shtml" without actually visibly redirecting. After a bit of poking around, it seemed as if this .htaccess command should do the trick:

RewriteEngine On
RewriteBase /

RewriteRule index.html index.shtml [L]
...but while it DOES seem to do what I want it to on one domain, on another I keep getting visibly forwarded to index.shtml. Am I missing something here?


If you're curious, I want to do this because my host (DH) only runs files with an .shtml extension through the SSI parser by default. I have largely static pages, so this is good--no extra time parsing what doesn't need it. But now I'm trying to add a little SSI directive to the main index page for the entire domain. Up to now, I'd been using index.html for that, and I don't want to affect the links to such. But if I do a standard "Redirect 301" statement, when somebody hits the domain without anything after the first / it tacks on index.shtml instead of leaving it "bare". I prefer the "bare" style, and I also don't really want to be visibly redirecting to .shtml, either.

The funny thing is when I added the above to the .htaccess on a test domain, it worked absolutely perfectly. When I did it on my main domain, no go.

If there were a way to use an AddHandler directive in .htaccess to run only one specific filename through the SSI parser rather than ALL .html files, that would do the trick too, of course, but I don't see that that's an option, either.
 
Ok, I'm a complete raging idiot. The reason it wasn't doing what I thought it should was I had left a Redirect directive above it in the .htaccess file, so it was getting redirected before it was getting rewritten.

I'm still a bit stuck, though, since that directive remaps EVERY index.html rather than just the root one. I thought the RewriteBase setting would fix that, but I was obviously wrong.

[Edit: Ok, think I got it; I needed a ^ before the index.html; I had it in there originally but had removed it in the process of confused testing.]
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.