htacces 提供缓存文件
我有一个用于 php 应用程序的文件缓存系统。如果文件需要缓存,我将其作为平面 html 保存到缓存目录中,模仿 request_uri 的目录结构,
在正常继续之前,我如何检查 htaccess 中是否有平面文件?目前我检查 php,但理想情况下,如果有缓存文件,我不希望在该请求上运行服务器端代码。
我当前的设置通过索引文件路由所有内容,然后 php 根据 uri 确定要包含哪些文件。
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
所以说,一个请求进来了,
http://localhost/posts/45/the-name-of-my-post/
or
http://localhost/posts/45/the-name-of-my-post
我如何检查是否有一个平面 html 文件,
app/tmp/cache/posts/45/the-name-of-my-post/index.html
谢谢,抱歉,如果这是一个愚蠢的问题,我对重写规则相当新手。如果有人有更好的想法如何从缓存的请求中消除 php 代码,我愿意接受任何事情。
好的,现在尝试
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond ^app/tmp/cache/%{REQUEST_URI} -d
RewriteRule (.*) ^app/tmp/cache/%{REQUEST_URI}
# map everything to the index file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond ^app/tmp/cache/%{REQUEST_URI} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
尝试这个,但似乎不起作用,我忽略了什么?
我的请求是
http://localhost/posts/view/23/another-post/
尝试提供服务
http://localhost/app/tmp/cache/posts/view/23/another-post/
I have a file caching system for a php application. if a file needs cached i save it to a cache dir as flat html mimicking the directory structure of the request_uri
how could i check with htaccess if there is a flat file in this cache dir before continuing as normal? currently i check with php, but ideally if there is a cached file, i would like to have no serverside code run on that request.
my current setup routes everything through the index file and then php determines what files to include based on the uri.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
so say that a request came in as
http://localhost/posts/45/the-name-of-my-post/
or
http://localhost/posts/45/the-name-of-my-post
how would i check to see if there is a flat html file located in
app/tmp/cache/posts/45/the-name-of-my-post/index.html
thanks and sorry if this is a stupid question, im fairly novice with rewrite rules. If anyone has a better idea how to elimimate php code from a cached request, im open to anything.
ok now trying
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond ^app/tmp/cache/%{REQUEST_URI} -d
RewriteRule (.*) ^app/tmp/cache/%{REQUEST_URI}
# map everything to the index file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond ^app/tmp/cache/%{REQUEST_URI} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
tried this but doenst seem to be working, what am i overlooking?
my request is
http://localhost/posts/view/23/another-post/
trying to serve up
http://localhost/app/tmp/cache/posts/view/23/another-post/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
RewriteCond %{REQUEST_FILENAME} !-f
该语句已经表示“如果请求的文件不存在,则继续执行下一条语句,否则检索它”
RewriteCond %{REQUEST_FILENAME} !-f
That statement already says "if the requested file doesn't exist go on to the next statement, else retrieve it"