Mainul Hasan
Mainul Hasan

Reputation: 49

Redirect question mark URL to the original URL

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.

Upvotes: 2

Views: 163

Answers (2)

anubhava
anubhava

Reputation: 785058

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

Upvotes: 1

Ambrish Pathak
Ambrish Pathak

Reputation: 3968

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

Upvotes: 0

Related Questions