wordpress如何实现nginx多站重写规则

2024年09月27日 建站教程

wordpress如何实现nginx多站点rewrite重写规则,下面web建站小编给大家详细介绍一下具体实现方法!

wordpress实现多站点子目录重写规则

map $uri $blogname{
  ~^(?P/[^/]+/)files/(.*)	$blogpath ;
}
 
map $blogname $blogid{
  default -999;
 
  #Ref: http://wordpress.org/extend/plugins/nginx-helper/
  #include /var/www/wordpress/wp-content/plugins/nginx-helper/map.conf ;
}
 
server {
  server_name ipkd ;
 
  root /var/www/ipkd/htdocs;
  index index.php;
 
  #多站点配置
  location ~ ^(/[^/]+/)?files/(.+) {
    try_files /wp-content/blogs.dir/$blogid/files/$2 /wp-includes/ms-files.php?file=$2 ;
    access_log off;  log_not_found off; expires max;
  }
 
  #avoid php readfile()
  location ^~ /blogs.dir {
    internal;
    alias /var/www/ipkd/htdocs/wp-content/blogs.dir ;
    access_log off;  log_not_found off; expires max;
  }
 
  if (!-e $request_filename) {
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;  
    rewrite ^(/[^/]+)?(/wp-.*) $2 last; 
    rewrite ^(/[^/]+)?(/.*.php) $2 last; 
  }
 
  location / {
    try_files $uri $uri/ /index.php?$args ;
  }
 
  location ~ .php$ {
    try_files $uri =404;
    include fastcgi_params;
    fastcgi_pass php;
  }
 
  #此处可以继续添加伪静态规则
}

<h3wordpress实现多站点二级域名重写规则

map $http_host $blogid {
  default     -999;
 
  #Ref: http://wordpress.org/extend/plugins/nginx-helper/
  #include /var/www/wordpress/wp-content/plugins/nginx-helper/map.conf ;
 
}
 
server {
  server_name ipkd *.ipkd ;
  
  root /var/www/ipkd/htdocs;
  index index.php;
  
  location / {
    try_files $uri $uri/ /index.php?$args ;
  }
  
  location ~ .php$ {
    try_files $uri =404;
    include fastcgi_params;
    fastcgi_pass php;
  }
  
  #WPMU Files
  location ~ ^/files/(.*)$ {
  try_files /wp-content/blogs.dir/$blogid/$uri /wp-includes/ms-files.php?file=$1 ;
  access_log off; log_not_found off;    expires max;
  }
  
  #WPMU x-sendfile to avoid php readfile()
  location ^~ /blogs.dir {
    internal;
    alias /var/www/ipkd/htdocs/wp-content/blogs.dir;
    access_log off;	log_not_found off;	expires max;
  }
  
  #此处可以继续添加伪静态规则
}

本文链接:http://so.lmcjl.com/news/14039/

展开阅读全文
相关内容