【发布时间】:2015-11-11 00:59:30
【问题描述】:
我正在阅读有关通过重定向(例如 $1?$argument 到 $1)从所有请求中删除查询字符串/参数的信息。
我尝试了文档中所说的在所需重写的末尾添加 ? 以删除查询字符串和参数,但这没有效果。
我希望保持当前功能,并从所有 URI 请求中删除查询字符串/参数。
与文档中关于附加? 的建议有什么冲突,或者对此的正确解决方案是什么?
# for removing .php from all requests
location / {
try_files $uri $uri/ @extensionless-php;
}
# rewrite to remove .php
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
# deny access to php includes
location ~* /includes/(.+)\.php$ {
deny all;
}
# redirect all instances of index.php to / in its respective directory (for example, /index.php to /, and /articles/index.php to /articles/)
location ~* \.php {
try_files $uri =404;
if ($request_uri ~ ^/([^?]*?)(?:(?<=/)index(?:\.php)?|\.php)(\?.*)?$) { return 301 /$1$2; }
fastcgi_pass backend;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
【问题讨论】:
标签: nginx url-rewriting rewrite