Redirect URL with Query String using RedirectMatch

I'm trying to use RedirectMatch to redirect URLs with a question mark left over from an SEO plugin. Our vbulletin 4.2.5 forum is using Dragonbyte SEO to rewrite URLs but some external sites are still linking to the old URLs. We also have a strange issue with an equal sign being appended to some URLs which also breaks things. I've been trying to create redirect rules for these issues but everything I've tried seems to either cause an error or not work at all. I'd really appreciate any assistance I could get with this.

Example URL: http://subdomain.example.com/content/?123-My-Article-Title

Desired Redirect: http://subdomain.example.com/content/123-My-Article-Title.html

Live Server: LiteSpeed Test Server: Apache 2.4.27

example .htaccess attempts:

RewriteRule ^(\/content\/)\?([0-9]*[-a-z,A-Z]*)$ http://subdomain.example.com/$1$2.html [R=302, L]

RedirectMatch 302 /content/?([0-9]*[a-zA-Z-]*) http://subdomain.example.com/$1.html

1 answer

  • answered 2018-04-17 04:06 starkeen

    You can not redirect querystring using RedirectMatch directive. You need to match against %{QUERY_STRING} variable using mod-rewrite .

    RewriteEngine on
    
    RewriteCond %{QUERY_STRING} ^(.+)$
    RewriteRule ^content/?$ http://Subdomain.example.com/content/%1.html? [L,R]