dszpyf4859 2010-02-28 01:40
浏览 34
已采纳

htaccess提供缓存文件

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/

  • 写回答

2条回答 默认 最新

  • dongping5230 2010-02-28 02:16
    关注

    Try this:

    RewriteCond app/tmp/cache/%{REQUEST_URI} -d
    RewriteRule (.*) app/tmp/cache/%{REQUEST_URI}/
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用