Forum Moderators: phranque
Options +FollowSymLinksRewriteEngine 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
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
RewriteCond %{REQUEST_FILENAME} !-s
Thanks again!
Wing