This is because "?" is not interpreted as a literal character or part of the filename if not after "?filename=" in IPFS gateways. Memento doesn't work with "?filename=", so there's no way to correctly do that specifically with IPFS gateways. %3F in the URL is the only way to get it to correspond to a question mark character in the filename for the path-based and not CID-based address. Solution? Use ipwb WARC replay thing which probably will work with https://example.com/index.php?q=123 (and even show it has having been captured via HTTPS and not HTTP). Or use some other webserver like Apache or nginx.