httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ramsey, Robert L" <>
Subject [users@httpd] help with rewrite rule
Date Tue, 01 Mar 2005 18:07:27 GMT

I was reading through the rewrite rules guide at and I came across an
example that I think will do exactly what I want, but I'm not sure I
understand how to implement it.

Here's my goal:

The file system is typical:
/var/www/html  is document root

A user types in  I want to rewrite
that so that it goes to:


If I have to put this script in the document root, I can, but would
prefer not to.  myscript.php then checks in this order:

1)  If the file really does exist in /var/www/html/path/to/file.php,
then change the location to that file.
2)  If the file exists as an entry in a database, load the file from the
database and present that to the user.
3)  If the file does not exist in either place, then return 404.

Naturally, all GET and POST variables should be passed along.  And the
user should always see the address that was originally typed in.

There's an example on On-The-Fly content generation:

On-the-fly Content-Regeneration

    Here comes a really esoteric feature: Dynamically generated but
statically served pages, i.e. pages should be delivered as pure static
pages (read from the file system and just passed through), but they have
to be generated dynamically by the web server if missing. This way you
can have CGI-generated pages which are statically served unless one (or
a cronjob) removes the static contents. Then the contents gets
    This is done via the following ruleset:

RewriteCond %{REQUEST_FILENAME}   !-s
RewriteRule ^page\.html$          page.cgi

    Here a request to page.html leads to a internal run of a
corresponding page.cgi if page.html is still missing or has filesize
null. The trick here is that page.cgi is a usual CGI script which
(additionally to its STDOUT) writes its output to the file page.html.
Once it was run, the server sends out the data of page.html. When the
webmaster wants to force a refresh the contents, he just removes
page.html (usually done by a cronjob).

But I'm not sure how to alter it to do what I want.  I don't want the
page created, but I do want the script to run and the user to see the
same page that was entered.

Any pointers?



The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message