Closed nibazshab closed 1 year ago
Thanks, I'll revert this then
location ~* ^/notes/([a-zA-Z0-9_-]+)$ {
try_files $uri /notes/index.php?note=$1;
}
With the current nginx
configuration when there are directories, the ?raw
parameter cannot be passed.
In other words, when accessing /notes/test?raw
, it only becomes /index.php?note=test
While the previous configuration would actually result in /index.php?note=test?raw
location ~* ^/notes/([a-zA-Z0-9_-]+)$ {
try_files $uri /notes/index.php?note=$1$is_args$args;
}
Because $is_args
has a value of ?
when there are parameters
Therefore, the configuration logic that can actually pass parameters might be like this:
location ~* ^/notes/([a-zA-Z0-9_-]+)$ {
set $args_append "";
if ($is_args) { # if 块有问题,改为 map
set $args_append "&$args";
}
try_files $uri /notes/index.php?note=$1$args_append;
}
However, the if
block can be problematic. If Is Evil
So, try using the map directive in the HTTP block
context to create a new variable $args_append
The map
directive is defined in the http
block of the configuration and can create more reliable conditional variables at an early stage of request processing.
http {
map $is_args $args_append {
default "";
"?" "&$args";
}
server {
# ... other server configurations ...
location ~* ^/notes/([a-zA-Z0-9_-]+)$ {
try_files $uri /notes/index.php?note=$1$args_append;
}
}
}
This way, parameters can be passed normally without errors. Of course, it seems that directly writing it as:
location ~* ^/notes/([a-zA-Z0-9_-]+)$ {
try_files $uri /notes/index.php?note=$1&$args;
}
also doesn't seem to have any issues. After testing, both methods work. I don't have a better solution. This is just for discussion.
Apache all is OK, but Nginx not.
Use
$is_args$args
, urlxxx
and argument?raw
will become urlxxx?raw
, it then be matched by!preg_match('/^[a-zA-Z0-9_-]+$/', $_GET['note'])
and be rewrited. So just need remove it.I've already tested it.
So maybe https://github.com/pereorga/minimalist-web-notepad/commit/38459b4d713d4a18098ab669166239030851487d is not a good idea