The recordset should not have any effect on the rewrite rule.
The URL rewrite is done before the page is accessed.
the path is:
-go to address
-server rewrites address to requerst page
-page is executed.
the 404 error means the page cannot be found by the server.
the recordset has not even been executed at that time.
It cannot have anything to do with the recordset using MySQLi, the server is saying it cannot find the page. It would need to first find the page to execute the recordset.
not posible that the MySQLi recordset is the cause of the problem.