首页 - 所有文章 - 玩转服务器 - 正文

WordPress多站点Nginx伪静态规则

目前盛龙科技用的WordPress多站点Nginx伪静态规则是下面这个

# wordpress固定链接设置
  try_files $uri $uri/ /index.php?$args;

  # 管理面板添加斜杠
  rewrite /wp-admin$ $scheme://$host$uri/ permanent;

  # 传递上传文件给 wp-includes/ms-files.php
  rewrite /files/$ /index.php last;

  # 重写多站点 '.../wp-.*' and '.../*.php'.
  if (!-e $request_filename) {
    rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
    rewrite ^/[_0-9a-zA-Z-]+.*(/wp-admin/.*\.php)$ $1 last;
    rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
  }

另外一个规则如下供参考

#ignored: “-” thing used or unknown variable in regex/rew
rewrite ^/([_0-9a-zA-Z-]+/)?wp-admin$ /$1wp-admin/ permanent;
if (-f $request_filename){
set $rule_2 1;
}
if (-d $request_filename){
set $rule_2 1;
}
if ($rule_2 = "1"){
#ignored: “-” thing used or unknown variable in regex/rew
}
rewrite ^/([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) /$2 last;
rewrite ^/([_0-9a-zA-Z-]+/)?(.*.php)$ /$2 last;
rewrite /. /index.php last;