Have only ONE specific page parsed by SSI?


#1

I searched around the forum and tried asking Google and didn’t come up with anything, so here goes:

I’ve got one (and only one) file on my site that I’m wanting to add a small SSI include directive to. What I want to do is pretty simple: Get that page parsed but none of the others, and have it otherwise behave exactly as it has in the past.

Problem: A heap of links out there already point to index.html, not index.shtml.

Setting all .html files to get run through SSI is a total waste of processor, so that’s out. I could use the XBitHack to do it, but the problem with that is my FTP software has a tendency to set the executable bit on HTML uploads, so I don’t want to end up unnecessarily processing a heap of pages because of that, either.

I can (and for now, have) used an .htaccess line to redirect index.html to index.shtml, but the problem with that is if you go to the top level of the site (http://site.com/), instead of leaving it blank after the trailing slash it ends up tacking the full index.shtml on.

Yes, that’s not a horrible thing, but isn’t there some .htaccess trickery that can run just one file through the SSI parser?


#2

.shtml should be parsed for ssi by default, where .html should not. if the file you want to use ssi for is an index file, you can still name it index.shtml, and just put this line in .htaccess if it doesn’t work like index.html would:

Directory Index index.shtml index.html index.htm index.php

you can list as many filenames you want – in the example above it will look for index.shtml, or if it doesn’t find that, index.html, and so on. i can’t remember if this rule applies to subdirectories or not, so make sure that if you’re using index.html in subdirectories you include it here to be safe.

track7 - my dream-hosted site


#3

And along with this, if you have incoming links that currently point to /index.html and you need to make that file SSI-enabled, just rename it to /index.shtml and set up a .htaccess file with a RewriteRule redirecting requests for /index.html to /index.shtml.


#4

I appreciate both suggestions. As I said, getting it to use the index.shtml file isn’t a problem–that is indeed automatically set up. It’s just that I wanted to map index.html to index.shtml WITHOUT having it visibly redirect–just wanted to keep the bare / after the domain or, if the person went to index.html directly, leave it at that.

So the suggestion from to use mod_rewrite to do this seemed quite logical. Except for some reason the rewrite rule that SEEMS it should work, and DID on a test domain doesn’t seem to be doing the trick on my main one. Am I doing something wrong with this .htaccess command?

RewriteEngine On
RewriteBase /

RewriteRule index.html index.shtml [L]

…shouldn’t that transparently remap index.html to index.shtml without a redirect, or am I totally confused about how this should work?


#5

i believe [L] means send the location header, which will change the url from index.html to index.shtml. try it without [L]

track7 - my dream-hosted site


#6

The [L] means that this should be the last rule applied, that the rewriting process should stop here. You’re thinking of [R], which sends an HTTP redirect to the client instead of handling it internally. You often see the two of these used together because when redirecting the client elsewhere, you want it to happen immediately, without going through further rewrite rules.

A detailed explanation of mod_rewrite flags is available in the documentation.


If you want useful replies, ask smart questions.


#7

Oh MAN am I an idiot. I’d already read through the documentation, which is where the [L] flag came from in the right place.

Turns out the rule I posted above was the right one (well, if you add a ^ to the begining, anyway); I had just somehow forgotten to remove the Redirect above it in the .htaccess file, which is also why my test domain worked and the live one didn’t.

Big thanks to aixccapt99 for pointing me at mod_rewrite to do what I wanted.