Peter
Peter

Reputation: 1

Redirecting Specific URL pattern using REGEX

I'd like to redirect the URL's

https://old-URL.com/index.php?topic={integers} to https://new-URL.com/index.php?topic={integers}

I've tried:

RewriteEngine On    
RewriteRule ^\/index\.php\?topic=(.*) https://new-URL.com/ [R=301]

But I can't seem to get it for the life of me.

Upvotes: 0

Views: 40

Answers (1)

Amit Verma
Amit Verma

Reputation: 41209

You can not match against URL QueryString ( ?topic=val ) in pattern of a RewriteRule. You need to use RewriteCond for that .

RewriteEngine on

RewriteCond %{QUERY_STRING} ^topic=(.+)$ [NC]
RewriteRule ^index.php$ http://newurl.com/index.php?topic=%1 [L,R,NE]

Upvotes: 2

Related Questions