httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott Lamb <>
Subject mod_rewrite: Rewriting .html to .shtml if no .html exists
Date Thu, 15 Aug 2002 00:19:49 GMT
I'm trying to make .html URLs work whether a page is preprocessed with 
SSI or not. (While not invoking the overhead of pre-processing all .html 

Here's how I'm trying to do it:

     RewriteEngine On
     RewriteLog /tmp/rewrite.log
     RewriteLogLevel 9

     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^(.*)\.html$ $1.shtml

But it doesn't work. This _always_ rewrites the URL. The log says this:

     (2) init rewrite engine with request uri /index.html
     (3) applying pattern '^(.*)\.html$' to uri '/index.html'
     (4) RewriteCond: input='/index.html' pattern='!-f' => matched
     (2) rewrite /index.html -> /index.shtml
     (2) local path result: /index.shtml
     (2) prefixed with document_root to
     (1) go-ahead with /var/www/ [OK]

The index.html does exist. The full path is 

Am I doing something wrong, or is this a bug? I've also tried using a 
couple different conditions:

     RewriteCond %{REQUEST_FILENAME} !-F
     RewriteCond %{REQUEST_URI} !-U

They say different things in the log, but they either pass or fail _all_ 
the time, not based on whether there actually is a .html file present.

The -F check says this:

     (5) RewriteCond file (-F) check: path=/index.html ->
         file=/index.html status=200
     (4) RewriteCond: input='/index.html' pattern='!-F' => matched

Status 200 means the file was found, right? So why did a !-F match?

And the -U check says this:

     (5) RewriteCond URI (-U) check: path=/index.html -> status=200
     (4) RewriteCond: input='/index.html' pattern='!-U' => not-matched

That's correct. But when I try it with a page where the .html doesn't 
exist and the .shtml does:

     (5) RewriteCond: URI (-U) check: path=/test.html -> status=200
     (4) RewriteCond: input='/test.html' pattern='!-U' => not-matched

Why was the status 200? That file does not exist. (Does it attempt to 
apply these rules recursively?)

Scott Lamb

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message