我正在尝试使用wordpress和Nginx运行多域博客安装.最后一步是在.htaccess(仅限apache)中为Web服务器配置一些重写规则.如何将其转换为Nginx重写规则?
RewriteEngine On
RewriteBase /
RewriteRule ^index\.PHP$- [L]
# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.PHP?file=$1 [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.PHP [L]
最佳答案
nginx rewrite rules example for WordPress 3:
原文链接:https://www.f2er.com/nginx/434860.htmlserver{
server_name *.example.com;
listen 80;
#on server block
##necessary if using a multi-site plugin
server_name_in_redirect off;
##necessary if running Nginx behind a reverse-proxy
port_in_redirect off;
access_log /var/log/Nginx/example-com-access.log;
location / {
root /var/www/example.com/wordpress;
index index.html index.htm index.PHP;
rewrite ^.*/files/(.*)$/wp-includes/ms-files.PHP?file=$1 last;
if (!-e $request_filename) {
rewrite ^.+/?(/wp-.*) $1 last;
rewrite ^.+/?(/.*\.PHP)$$1 last;
rewrite ^(.+)$/index.PHP?q=$1 last;
}
}
location ~* ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$
{
root /var/www/example.com/wordpress;
rewrite ^/.*(/wp-.*/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$$1 last;
rewrite ^.*/files/(.*(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$/wp-includes/ms-files.PHP?file=$1 last;
expires 30d;
break;
}
location ~ wp\-.*\.PHP|wp\-admin|\.PHP${
include /etc/Nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME /var/www/example.com/wordpress$fastcgi_script_name;
}
}