[users@httpd] help with rewrite rule

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I was reading through the rewrite rules guide at
http://httpd.apache.org/docs/misc/rewriteguide.html 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
/var/www/cgi-bin
/var/www/php

A user types in http://mysite.com/path/to/file.php.  I want to rewrite
that so that it goes to:

/var/www/php/myscript.php  

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

Description:
    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
refreshed.
Solution:
    This is done via the following ruleset:

RewriteCond %{REQUEST_FILENAME}   !-s
RewriteRule ^page\.html$          page.cgi
[T=application/x-httpd-cgi,L]

    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?

Thanks,

Bob

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux