skip to Main Content

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


  1. 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

    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search