WordPress How to rewrite URL for custom pages

Assuming this is completely outside of WordPress then… to rewrite /test/test/123/dnfjk to /test/test.php?id=123&z=dnfjk, then you could do something like the following in the /test/.htaccess file (not the WordPress .htaccess file in the document root):

Options -MultiViews

RewriteEngine On
RewriteRule ^test/(\d+)/([a-z]+)$ test.php?id=$1&z=$2 [L]

MultiViews needs to be disabled for this to work.

RewriteRule ^(.*).html$ https://example.com/$1 [R=301,L]
RewriteRule ^(.*).htm$  https://example.com/$1 [R=301,L]
RewriteRule ^(.*).php$  https://example.com//$1 [R=301,L]

These are external redirects (as opposed to internal rewrites) and don’t seem to relate to your example at all?

Note that you change the URL in your application, you don’t issue a redirect to do this. You would only need the redirect if the old URL (with URL parameters) had already been indexed and/or linked to by third parties.