Forum Moderators: phranque

Message Too Old, No Replies

statically cache dynamic scripts

         

winglian

3:25 am on Dec 4, 2003 (gmt 0)

10+ Year Member



First off, here is my .htaccess file

Options +FollowSymLinks

RewriteEngine On
RewriteBase /
RewriteRule ^(.+/)?(_[^/]*)/(.*)$ $1$3

RewriteCond %{REQUEST_URI} ^(.*/)?([^/]*.html)$
RewriteRule ^(.*/)?([^/]*.html)$ cache/$2

RewriteCond %{REQUEST_URI}!-f
RewriteRule ^(.*/)?(.[^/]*).html$ phpinfo.php?html=$2 [L]

Basically, what these rewrites do is strip out any sub-directories that start with an _underscore. Then, if the filename has an .html extension, then the URI is rewritten as cache/filename.html. The last condition is where I am having problems. I have tried!-U ,!-f ,!-F ,!-s , as well as various different extensions to check if the filename exists. Whether or not the filename exists, it still returns the phpinfo.php script. However, if I comment out the last rule, then if the page does exist, then it shows the cached/static page, but if the file doesn't exist, I get a 404 error (as expected). Is there something wrong with the RewriteCond that doesn't verify the filename correctly?
Also, If remove the!(negate) from the RewriteCond and leave the last RewriteRule uncommented, then the phpinfo never loads (which is not expected) and I either get the cached page or a 404 error.
Based on this, it seems that the -{char} is always false, thus it doesn't run the RewriteRule, and the!-{char} is always true, thus it always loads the RewriteRule

Eventually I will replace phpinfo.php with a script to regenerate the dynamic content, but for now phpinfo is a great debug tool for this. I don't want to use an ErrorDocument 404 type line since I want to avoid 404's for seo purposes.

Thanks Again!
Wing Lian

jdMorgan

7:32 am on Dec 4, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wing,

This is pretty strange, since I've used -U and -f several times without trouble.

You could also try it with %{REQUEST_FILENAME} and see if that changes anything.
[edit]
RewriteCond %{REQUEST_FILENAME} !-f
[/edit]
Either way, %{REQUEST_XX} is going to test the requested path, not the modified path.
(You can set an environment variable using RewriteRule to get around that)

Jim

winglian

3:22 pm on Dec 4, 2003 (gmt 0)

10+ Year Member



Well, that is just strange and everything. The funny thing is if they only test the original requested string, then I have alot of work to do with env variables. However, I jsut tried sticking in

RewriteCond %{REQUEST_FILENAME} !-s

into the code not expecting it to work since the document I would be calling doesn't exist, and lo and behold, it worked!

Thanks again!
Wing