nginx - 禁用某些目录的规则
问题描述
我正在使用这个规则:
if ($request_uri ~ ^/([^?]*)\.(php|html|htm)($|\?)) {
return 302 /$1?$args;
}
删除 URL 的 .php/.html/.htm 扩展名,现在我想为这样的目录禁用此规则:/site/ajax
。
这是我的完整服务器配置:
server {
server_name www.example.net;
listen 443;
root /var/www/html;
index index.php;
ssl on;
ssl_certificate /path/cert.pem;
ssl_certificate_key /path/privkey.pem;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location /site/ajax/ {
index index.php;
break;
}
#Remove .php | .html | .htm
if ($request_uri ~ ^/([^?]*)\.(php|html|htm)($|\?)) {
return 302 /$1?$args;
}
location / {
try_files $uri $uri/ $uri.html $uri.php?$args;
}
location /site/query {
try_files $uri $uri/ $uri.html $uri.php?$args;
index manage.php; #Change index for query folder
}
error_page 404 /404.html;
error_page 403 /403.html;
access_log /var/log/nginx/nginx.vhost.access.log;
error_log /var/log/nginx/nginx.vhost.error.log;
}
这可能吗?
解决方案
一种解决方案是在正则表达式中使用否定的前瞻断言。例如:
^/(?!site/ajax)([^?]*)\.(php|html|htm)($|\?))
推荐阅读
- naming-conventions - 我应该为具有特定角色的按钮命名变量
- c++ - 霍夫曼编码 C++ 代码引发致命错误
- c# - 如何调试 IFixtureBuilder 的自定义实现?
- python - 尝试在 python 中构建数据框时出现语法错误
- mysql - PDF 中的正确 SQL 语句?
- r - 将 ggplot2 图形绘制为多个 jpg,文件名为主题 ID
- linux - 如何杀死陷阱中的进程组?
- javascript - 使用函数格式化日期时出错
- google-cloud-platform - 数据目录中的 Google Cloud DLP 标记显示为待处理的作业状态?
- javascript - 根据选择值隐藏和显示列表项