Return-Path: Delivered-To: apmail-httpd-users-archive@httpd.apache.org Received: (qmail 2515 invoked by uid 500); 16 Apr 2002 23:27:59 -0000 Mailing-List: contact users-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: users@httpd.apache.org list-help: list-unsubscribe: list-post: Delivered-To: mailing list users@httpd.apache.org Received: (qmail 2504 invoked from network); 16 Apr 2002 23:27:59 -0000 Received: from smithers.sfrn.dnai.com (208.59.199.26) by daedalus.apache.org with SMTP; 16 Apr 2002 23:27:59 -0000 Received: from sideshow-mel.sfrn.dnai.com (sideshow-mel.sfrn.dnai.com [208.59.199.19]) by smithers.sfrn.dnai.com (8.11.2/8.11.2) with ESMTP id g3GNO8067935 for ; Tue, 16 Apr 2002 16:24:08 -0700 (PDT) Received: from datawebsystems.com (208-59-198-132.s132.tnt1.dsfr.ca.dialup.rcn.com [208.59.198.132]) by sideshow-mel.sfrn.dnai.com (8.11.3/8.11.3) with ESMTP id g3GNMkd43828 for ; Tue, 16 Apr 2002 16:22:46 -0700 (PDT) (envelope-from davidp@datawebsystems.com) Message-ID: <3CBCB44E.2D340D52@datawebsystems.com> Date: Tue, 16 Apr 2002 16:31:26 -0700 From: David Pellegrini Organization: dataweb systems, inc. X-Mailer: Mozilla 4.72 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 To: users@httpd.apache.org Subject: Use of env vars in httpd.conf wrt mod_rewrite Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N I searched the FAQ and skimmed the last four months of the mailing list archives, and did not find the answer to this question, so I'm posting to the list in hopes that someone can help while I keep searching. Background: I'm setting up SSI and some rewrite rules so that all requests for static html pages get served via a standard page template. This allows my content developers to write very simple html without having to worry about overall page layout, as well as improving modularity, reuse, ripple effect of changes to the standard layout, etc, etc, Mom, and apple pie. I've got all that working great with just a couple of directives. In httpd.conf I have a rewrite rule to route html requests to my template, passing the requested file as an env var: RewriteRule (.*\.html) /template.shtml [NS,E=FileName:$1] template.shtml has all of the header, footer and navbar html. Then the "body of the page" is included thusly: Simple and elegant -- just the way I like it. Problem: I want to check first that the requested file exists before doing the magic to wrap the file in the standard page template. I want to return 404 rather than displaying the page template with "[an error occurred while processing this directive]" (the result of "#include virtual" looking for a non-existent file). My first attempt used RewriteCond to check with -f RewriteCond %{REQUEST_FILENAME} -f RewriteRule (.*\.html) /template.shtml [NS,E=FileName:$1] However, it appears that the RewriteCond is evaluated without the benefit of the DocumentRoot appended at the beginning. I can see evidence of that in the rewrite log file. It always fails to match. Most of the apache doc examples I've reviewed includes the document hardcoded into the ReWriteCond record like this: RewriteCond /my/document/root/path/%{REQUEST_FILENAME} -f This works, but it's ugly, and repeats information I've already hardcoded in the DocumentRoot directive. If I move my document root, I have to remember to update my RewriteCond's as well (and what are the chances of that happening the first time?). Ideally I'd just dereference the value of DocumentRoot in my RewriteCond record, but I don't know how to do that (or if it's possible). So that's question #1. As an alternative, I tried using SetEnv to establish the document root, then dereference it in the DocumentRoot and RewriteCond records, but that doesn't work. Example: ServerName vhost1.domain.com SetEnv vhost1Root /my/document/root/path DocumentRoot %{vhost1Root} Options Includes RewriteEngine on RewriteLog /var/log/httpd/vhost1-rewrite.log RewriteLogLevel 9 RewriteCond %{ENV:vhost1Root }/%{REQUEST_FILENAME} -f RewriteRule (.*\.html) /template.shtml [NS,E=FileName:$1] This does not work. First, no substitution occurs in the DocumentRoot record. Second, the %{ENV:DevelopmentRoot} in the RewriteCond record evaluates to the empty string. What is the magic incantation? How do I dereference an env var within httpd.conf? Is what I'm attempting even possible? Seems like it ought to be, but I've scoured the apache documentation and found nothing definitive. I've seen usage of SetEnvIf where the value of the env var is used later in httpd.conf, so I'm hopeful I'm on the right track, but right now I'm stymied. Any insight into a solution would be much appreciated. What's the "right" way to go about this? Thanks! -davidp --------------------------------------------------------------------- The official User-To-User support forum of the Apache HTTP Server Project. See for more info. To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org For additional commands, e-mail: users-help@httpd.apache.org