Rewrite URL for WordPress with htaccess for multiple query string parameters

Our main site is on WordPress. We have external links coming in with various query string parameters. Unfortunately, some of these interfere with WordPress (e.g. ‘s’ is reserved).

I would like to setup rewrite rules with htaccess since that is how I am already doing some things for the site. My issue is that I need to REPLACE the query string parameters with new names so they are not conflicting.

Read More

Possible Parameters and Mapping:

'l' -> 'li'
's' -> 'si'
'g' -> 'gi'
'i' -> 'ii'

These can come in any order but basically need to be replaced with the above mapping. An example:

FROM
http://www.domain.com/register?l=something&s=something (order not predictable)

TO
http://www.domain.com/register?li=something&si=something

Related posts

Leave a Reply

1 comment

  1. In your htaccess file before any rules you already have, add these:

    RewriteCond %{QUERY_STRING} ^(.*&)?s=(.*)$
    RewriteRule ^(.*)$ /$1?%1si=%2 [L]
    
    RewriteCond %{QUERY_STRING} ^(.*&)?l=(.*)$
    RewriteRule ^(.*)$ /$1?%1li=%2 [L]
    
    RewriteCond %{QUERY_STRING} ^(.*&)?g=(.*)$
    RewriteRule ^(.*)$ /$1?%1gi=%2 [L]
    
    RewriteCond %{QUERY_STRING} ^(.*&)?i=(.*)$
    RewriteRule ^(.*)$ /$1?%1ii=%2 [L]