Nginx location rewrite uses rules

A url https://www.example.com/knowledges/qa/123456 wants to proxy to https://www.example.com/knowledges/qa.html?id=123456

through Nginx

is configured in Nginx as follows:

root   /opt/statics;

location / {            
   index index.html;
}

location /knowledges/qa/ {
   rewrite ([^\/]+)\/?$ /knowledges/qa.html?questionId=$1 last;
}

where regular ([^\ /] +)\ /? $ matches to the last part of the url path, id. (see https://regex101.com/r/CBuz0o/1/)

Update
add a slash after / knowledges/qa / knowledges/qa/ , otherwise it will rewrite endless loop

can now be accessed normally, but the document.location obtained in qa.html is still the url, before Nginx forwarding, that is, https://www.example.com/knowledges/qa/123456. How can I get the url https://www.example.com/knowledges/qa.html?id=123456 forwarded by Nginx?

Mar.20,2021
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eab0b9-47de9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eab0b9-47de9.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?