如何使用的.htaccess重写使用请求的第一个字母一个缓存子目录? [英] How do I use .htaccess rewrite to a cache subdirectory using the first letter of the request?

查看:153
本文介绍了如何使用的.htaccess重写使用请求的第一个字母一个缓存子目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建动态生成的PHP文件静态的html文件的缓存方案。我目前使用PHP来检查缓存版本的存在,如果是这样我成为它和PHP退出。作为这个问题的(http://stackoverflow.com/questions/5612735/using-mod-rewrite-to-view-cached-version-from-usual-url),我觉得这是在浪费时间。不过,我有大约5000页,因此,我将preFER不要把他们都在同一个/缓存/目录。我反而喜欢把

I have a caching program that creates static html files of dynamically generated php files. I currently use php to check if the cached version exists, if it does I serve it up and php exits. As in this question (http://stackoverflow.com/questions/5612735/using-mod-rewrite-to-view-cached-version-from-usual-url), I feel this is a waste of time. However, I have around 5,000 pages and as such, I would prefer not to place them all in the same /cache/ directory. I would instead like to place

/a-web-url/ in /cache/a/a-web-url.html.gz

/this-is-another-url/ in /cache/t/this-is-another-url.html.gz

我目前正在与

I am currently working with

RewriteRule ^([A-Za-z0-9-_/\.]+)/$ /cache/$1

不过这个假设都是在同一个目录。我想preFER他们被分为若干子目录。谢谢你。

However this assumes that all are in the same directory. I would prefer them to be divided into subdirectories. Thanks.

另外请注意,我的所有文件末尾.html.gz

Also note that all of my files end in .html.gz

推荐答案

使用规则

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/?cache/ [NC]
RewriteRule ^/?(.)(.*?)/?$ /cache/${lc:$1}/${lc:$1}${lc:$2}.html.gz [L]

这篇关于如何使用的.htaccess重写使用请求的第一个字母一个缓存子目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆