对不起,我是nginx配置的新手,但是使用regexp可以。
现在我在自定义网站上拥有网址,例如
http_//domain.com/there-is-the-key?download=123456
并且我正在尝试将“?”之后的最后一部分硬重写,只希望关键字在URL中。这是我简单的nginx配置:
# if ($request_method !~* ^(GET|HEAD|POST)$ ){return 403;}
location ~ /\. {deny all;}
location / {
root "%hostdir%";
index index.php;
}
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php;
#HERE I'M ADDING NEW RULE#
break;
}
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
我试图添加这个
rewrite ^(.*)?download.* $1 last;
或者那个
rewrite ^(.*)?download[^\d]$ $1 last;
但没有-网址相同。