PHP 中的条件 URL 重写

发布于 2025-01-06 04:39:49 字数 415 浏览 4 评论 0原文

我编写了一个可以托管多个客户端/站点的自定义 CMS。站点及其各个部分存储在 /client-name/site-name 目录结构中。

htaccess 通过不存在的索引传递每个请求。

拥有“/clients/client-name/site-name/images/img.jpg”并不理想,因此为了仅允许“/images/img.jpg”,我捕获了请求,然后有效地提供真实位置文件的;标题和所有。我也在为 CSS、JS 等做这个。

这工作得很好,但是我现在注意到这不允许正确缓存文件,因此每次提供页面时,它都会再次加载整个内容,这很痛苦而且看起来很糟糕。

有谁知道解决这个问题的方法吗? Apache config 或 htaccess 解决方案都可以,但它需要知道文件的位置,该位置来自由 CMS 索引计算出的数据库。

帮助!

I've written a custom CMS that can host multiple client/sites. The sites and their various parts are stored within a /client-name/site-name directory structure.

The htaccess passes every request through the index that doesn't exist.

It's not ideal to have '/clients/client-name/site-name/images/img.jpg', so to allow just '/images/img.jpg' I've captured the request and I then effectively serve the real location of the file; headers and all. I'm doing this for CSS, JS etc too.

This has worked fine, however I'm now noticing that this doesn't allow the files to be cached properly, so every time a page is served it loads the whole thing again which is a pain and looks awful.

Does anyone know a way around this? Apache config or htaccess solution would be fine, but it needs to know the location of the file, which is from the DB worked out by the index of the CMS.

Help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

晨光如昨 2025-01-13 04:39:49

我通过 PHP 脚本提供 JavaScript(我用它来组合/缩小 JavaScript,以便我提供单个文件)。

我使用以下标头来确保它被缓存:

header('Content-type: text/javascript');
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 6048000));

在我的例子中,原始下载需要 982 毫秒。此后,每个后续请求只需 87 毫秒即可从缓存中获取数据 (Firefox 10.0.1)

I am serving up JavaScript through a PHP script (which I use to combine / minify the JavaScript so I serve a single file).

I use the following headers to ensure it gets cached:

header('Content-type: text/javascript');
header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 6048000));

In my case, the original download takes 982ms. After this it takes just 87ms to fetch from the cache for each subsequent request (Firefox 10.0.1)

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