我的网站流量过多,我想缓存部分网页,这样可以解决问题。
我已经有了这个系统,但问题是网址结构会导致1136.5万页保存在一个目录中,例如
dir / *< - 此目录中保存了11,000多页。
在删除目录时,这会使事情变得非常困难。
通过预测性搜索,我使用JavaScript来分解缓存,如:
people/joh/n-j/one/s.json
哪个更容易删除。
无论如何,我可以使用mod_rewrite以相同的方式拆分网址,例如。
/people/john-jones
caches/html/people/joh/n-j/one/s.html
是否存在,如果存在,我已经有了这个规则,但没有拆分:
RewriteCond %{SCRIPT_FILENAME} ^(.+)\/cache [NC]
RewriteRule .* - [E=PATH:%1]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^.+ %{ENV:PATH}/index.php?request=a&c=search&m=people&p=$0 [L]
答案 0 :(得分:1)
尝试以下规则:
RewriteEngine On
RewriteRule ^(people/.*?)([^/]{3})([^/]+)$ /$1$2/$3 [R=302,L]
RewriteCond %{DOCUMENT_ROOT}/caches/html%{REQUEST_URI}.html -f
RewriteRule ^ %{DOCUMENT_ROOT}/caches/html%{REQUEST_URI}.html [L]
OP建议的修改在peer review中被拒绝。以下是OP的解决方案:
# Set an environmental var for the root directory, so it works on local dev and live servers
RewriteCond %{SCRIPT_FILENAME} ^(.+)\/index.php$ [NC]
RewriteRule .* - [E=PATH:%1]
# Pick up the actual request from query string and set it as an environmental var
RewriteCond %{QUERY_STRING} ^request=names\/(.*?)([^/]{3})([^/]+) [NC]
RewriteRule .* - [E=SN:%1%2/%3]
# If a cache paged exists, internal redirect to that
RewriteCond %{ENV:PATH}/cache/html/names/%{ENV:SN}.html -f
RewriteRule .* cache/html/names/%{ENV:SN}.html [L]
# Send requests that are not cached to php
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^.+$ index.php?request=$0 [QSA,L]