Redirect question mark URL to the original URL

Viewed 60

I would like to redirect the following URL

https://www.example.com/vmi10/? to https://www.example.com/vmi10/

This is a WordPress site. How can I do that? I really appreciate any help you can provide.

2 Answers

You may use this redirect rule as your topmost rule in main .htaccess:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+[^?]*\?\s
RewriteRule ^ %{REQUEST_URI}? [L,NE,R=301]

# other WP rules below this line

Basically you want to remove empty query string from the url we use ^$ in our RewriteCond Condition Pattern like this:

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

This will redirect https://www.example.com/vmi10/? to https://www.example.com/vmi10/

This won't affect any url with non empty query string.

Test it here: https://htaccess.madewithlove.be?share=34570386-6b48-486b-ba84-32a222921502

Related