htacces 提供缓存文件

发布于 2024-08-23 08:55:52 字数 1280 浏览 3 评论 0原文

我有一个用于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

新人笑 2024-08-30 08:55:52

试试这个:

RewriteCond app/tmp/cache/%{REQUEST_URI} -d
RewriteRule (.*) app/tmp/cache/%{REQUEST_URI}/

Try this:

RewriteCond app/tmp/cache/%{REQUEST_URI} -d
RewriteRule (.*) app/tmp/cache/%{REQUEST_URI}/
天涯沦落人 2024-08-30 08:55:52

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"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文