我有一个php缓存系统(基于Zend Static Cache)...从动态页面创建静态html文件。它使用REQUEST_URI来创建文件名。 对于这样的REQUEST_URI /somedir/otherdir/file.html 它在缓存的目录(在我的服务器上)创建一个文件,如/cached/somedir/otherdir/file.html。
然后我使用htaccess将未来的请求重定向到静态文件(如果存在):
RewriteCond %{DOCUMENT_ROOT}/cached/%{REQUEST_URI}\.html -f
RewriteRule .* /cached/%{REQUEST_URI}\.html [L]
我遇到的问题是,当REQUEST_URI以“/”结尾时(基本上是一个目录),缓存会生成一个名为thedirectory.html的文件。
所以如果REQUEST_URI是/ thedirectory / ...我得到一个这个文件缓存/ thedirectory.html。
我如何将此类请求重定向到正确的文件。
感谢。 PS:我基本上跟着this article来实现我的缓存。我只在自定义的php应用程序上使用Zend Cache文件。
我想没有编辑php文件就没有好办法让这项工作成功。 以下是我使用Zend Cache的方法:
$tagCache = Zend_Cache::factory('Core', 'File', array('automatic_serialization' => true),
array('cache_dir' => $cfg['instdir']. 'Cache_dir'));
$cache = Zend_Cache::factory('Capture', 'Static', array(), array('public_dir' => $cfg['instdir']. 'Cached/',
'tag_cache' => $tagCache));
$id = bin2hex($name);
$cache->start($id, array());
是否有人知道哪些文件可能包含用于生成缓存文件名的代码?我编辑了几个前端,后端..但似乎没有发生任何事情。
我正在尝试做一些事情(就在ZEND获得REQUEST_URI之前):
if(substr($_SERVER["REQUEST_URI"],strlen($_SERVER["REQUEST_URI"])-1,1)=="/")
{
$ _ SERVER [ “REQUEST_URI”] = $ _ SERVER [ “REQUEST_URI”] “的index.html”;
}
也使缓存为目录添加index.html文件。
答案 0 :(得分:1)
尝试排除以下目录
#only if it is not a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/cached/%{REQUEST_URI}\.html -f
RewriteRule .* /cached/%{REQUEST_URI}\.html [L]
修改强>
我需要一个以/结尾的{REQUEST_URI}重定向到一个文件,该文件完全是{REQUEST_URI}而没有最后一个/(最后是.html)
尝试在.htaccess
中的任何现有规则之前添加此规则#redirect all requests with a trailing slash to the html versions
RewriteRule ^(.+)/$ $1.html [L,R=301]