是否有可能创build一个当前请求URI的MD5哈希string,并将其分配为一个ENVvariables,所以我可以从PHP读取?
我不testing,但你可以尝试:
RewriteEngine on RewriteMap md5create prg:/usr/local/sbin/md5create.pl RewriteRule ^(.*) %{REQUEST_URI} [E=MD5HASH:${md5create:$1}]
md5create.pl脚本创buildmd5sum
使用纯粹htaccess的基本caching的替代方法是从反映请求URI的caching中加载,实际上是将文件编译为dynamicURL指示的树结构。
例如:
Request: http://domain.com/foo/
文件结构:
Top Level: index.php,cache/ [Inside the cache/ directory -->] index.php, foo/
你明白了 – 这就像你正在build立一个静态网站,但是你已经把caching的网站版本存储在一个“caching”文件夹中。
然后你的.htaccess
# Add cache directory to request, store original request RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/?(.*)/?$ /cache/$1 [E=orig:$1] # Does the request exist as a directory in the cache folder? # Yes -> load the cached page RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d RewriteRule ^(.*)$ %{REQUEST_FILENAME} [L] # No -> continue with system rewrite RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/%{ENV:orig} [L]
把它们放在一起,这样可以改进,并依靠你的caching目录自动填充为文件结构,但认为它可能是有用的,因为它是纯粹的htaccess。
您的服务器端脚本需要更新caching文件结构并进行pipe理。
您可以通过使用全局variables$_SERVER["REQUEST_URI"]并使用内部PHP md5()函数来生成该variables。
如果你想每一次执行php代码,只要将php代码添加到php.ini中的auto_prepend_filevariables中即可。