Redirecting /px/?q=x to /px/x/

In your .htaccess add the following rule in between the <IfModule mod_rewrite.c> tag:

RewriteCond %{QUERY_STRING} ^q=(.*)$ [NC]
RewriteRule ^/?px/(.*)$ px/%1? [L,R=301]

Based off of the default .htaccess generated by WordPress, it should now look like the following with your custom RewriteRule:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# Custom Rules
RewriteCond %{QUERY_STRING} ^q=(.*)$ [NC]
RewriteRule ^/?px/(.*)$ px/%1? [L,R=301]
</IfModule>

Clear your browser’s cache and any domain that follows this structure:

http://example.com/px/?q=SLUG

Will redirect to:

http://example.com/px/SLUG

This has been verified and tested on my end using the htaccess tester.