LNMP=Linux+Nginx+Mysql+php,国内大部分是这样写的,国外也有写成LEMP的,其中E代表Nginx(egine X)。大部分PHP程序对于Rewrite规划都是针对Apache的,Apache的规划可以写在根目录.htaccess里,很容易被程序更新。Nginx的规划是写在配置文件里的,不能被程序直接访问到。

开启WP Super Cache后,更新.htaccess,把更新后的内容记录下来。

原规则不再此列出。

翻译成nginx支持的就是这样的,nginx rewrite rules for WordPress + WP Super Cache

location / {
 # enable search for precompressed files ending in  .gz
 # nginx needs to be complied using  –-with-http_gzip_static_module
 # for this to work, comment out if using  nginx from aptitude
 gzip_static on;

# if the requested file exists, return it immediately
 if (-f  $request_filename) {
 break;
 }
 if ($HTTP_USER_AGENT  ~* '(2.0\  MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\  Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\  Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\  OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\  CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\  Obigo|LGE\ VX|webOS|Nokia5800)') {
 rewrite . /index.php  last;
 }
 if ($HTTP_user_agent ~* '(2.0\  MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\  Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\  Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\  OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\  CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\  Obigo|LGE\ VX|webOS|Nokia5800)') {
 rewrite . /index.php  last;
 }
 set $supercache_file '';
 set $supercache_uri  $request_uri;

if ($request_method = POST) {
 set $supercache_uri  '';
 }

# Using pretty permalinks, so bypass the cache for any query  string
 if ($query_string) {
 set $supercache_uri '';
 }

if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" )  {
 set $supercache_uri '';
 }

# if we haven't bypassed the cache, specify our supercache  file
 if ($supercache_uri ~ ^(.+)$) {
 set  $supercache_file  /wp-content/cache/supercache/$http_host/$1index.html;
 }

# only rewrite to the supercache file if it actually exists
 if  (-f $document_root$supercache_file) {
 rewrite ^(.*)$  $supercache_file break;
 }

# all other requests go to WordPress
 if (!-e  $request_filename) {
 rewrite . /index.php last;
 }
}

测试,发现手机访问正常。

2010年10月24日更新:

在wp-supercache里,选择Use PHP to serve cache files后,可以省略以上的规则,只添加


location{
    if (!-e  $request_filename) {
        rewrite . /index.php last;
        }
    }

这么一个规则就可以了