I was reading around about removing query strings/arguments from all requests by way of redirection like $1?$argument
to just $1
.
I tried what the documentation said in adding a ?
to the end of the desired rewrite in order to remove query strings and arguments, but that had no effect.
I wish to maintain current functionality, and remove query strings/arguments from all URI requests.
What is conflicting with the documentation's suggestion of appending ?
, or what is the correct solution for this?
# 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;
}