Search code examples
wordpress.htaccessurlparametersquery-string

.htaccess redirect rewrite rule with slug and params coming from an old WordPress site


I moved away from a WordPress site and need to clean up some page redirects. Feel like this should be easier but I'm stuck on the slug with parameters, and can't find a good example to figure it out.

I simple need to create a .htaccess 301 redirect rule from...

https://same-domain.com/people/?g=Joe Smith

to

https://same-domain.com/item-list?people=Joe Smith

with "Joe Smith" being changing value.


Solution

  • Sounds pretty straight forward. You need a combination of a RewriteCond to capture the query string and a RewriteRule to perform the actual redirection:

    RewriteEngine on
    RewriteCond %{QUERY_STRING} ^g=(.*)$
    RewriteRule ^/?people/?$ /item-list?people=%1 [R=301,L]
    

    This will work in the central http server's configuration or likewise in a distributed configuration file (".htaccess") in the http host's DOCUMENT_ROOT folder.