-1

我尝试了很多组合,但没有一个有效。我试图编写重写规则:

  1. 假设 URL 为http://example.com/project/big_bunny
  2. 当用户访问站点重写首先尝试读取文件 /cache/project/big_bunny.html 但前提是没有任何获取或发布数据
  3. 如果没有缓存重写过程标准路由规则:index.php?_rt=$1 [L,QSA]

有什么建议么?

4

2 回答 2

0

Try this:

# Check if using POST method
RewriteCond %{THE_REQUEST} !^POST
# Check if already rewrote to cache
RewriteCond %{REQUEST_URI} !^/cache
# Check if cache exists
RewriteCond /cache%{REQUEST_URI}.html -f
# Check if contains any GET query string
RewriteCond %{QUERY_STRING} !.+
# Do the rewrite
RewriteRule ^/(.*) /cache/$1.html [L]

# Check if already rewrote to cache
RewriteCond %{REQUEST_URI} !^/cache
RewriteRule ^/(.*) index.php?_rt=$1 [L,QSA]
于 2012-07-04T06:31:49.093 回答
0

尝试这个:

# Check the cache, and rewrite if file exists
RewriteCond %{THE_REQUEST} !^POST [NC]
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI}.html -f
RewriteRule ^ /cache%{REQUEST_URI}.html [L]

# If URI doesn't start with /cache/, it wasn't cached so rewrite to index.php
RewriteCond %{REQUEST_URI} !^/cache/
RewriteRule ^(.*)$ index.php?_rt=$1 [L,QSA]
于 2012-07-04T06:20:14.257 回答