【发布时间】:2023-04-01 01:29:01
【问题描述】:
我是 Nginx 的新手,并试图将我为 WordPress 网站的以下规则从 Apache 转换为 Nginx。我从运行 Nginx 1.4.6 的 Ubuntu 机器上的默认 Nginx 配置开始。
RewriteCond %{REQUEST_URI} !^/wp-content/themes/path/to/exclude/file\.php
RewriteRule wp-content/themes/(.*\.php)$ log.php?f=$1 [L]
上述规则将所有对wp-content/themes/*.php 的请求重写为security-log.php,RewriteCond 规则中定义的文件除外。
据我所知,在 Nginx 中执行此操作的方法是使用 location 块。我尝试了以下方法(我仍然不确定如何排除特定文件/文件夹)。
location = /wp-content/plugins/(.*\.php)$ {
try_files /security-log.php =404;
}
上面的规则似乎被完全忽略了(也许我的正则表达式有问题?)。
如果我提供一个固定路径,如下所示,规则被调用,但 Nginx 将提供 PHP 文件(浏览器将下载文件)而不是使用 PHP 解释器执行它(很可能这是因为 fast-cgi 是没有被召唤)。
location = /wp-content/plugins/test.php {
try_files /security-log.php =404;
}
实现这一目标的最佳方法是什么?
【问题讨论】:
-
这个你试过了吗:winginx.com/en/htaccess
标签: php wordpress nginx nginx-location