The following .htaccess rule replaces "OLDNAME" with "NEWNAME" in a URL and it removes the string "-2" from the end of the URL if it exists. I need to update the rule to accommodate two scenarios: "OLDNAME1" and "OLDNAME2". Both redirect to a single "NEWNAME".
RewriteRule ^(index.php/)?OLDNAME/(.+?)(?:-2)?/?$ /NEWNAME/$2 [L,NC,R=302,NE]
I’ve tried several variations of the following:
RewriteRule ^(index.php/)?(OLDNAME1|OLDNAME2)/(.+?)(?:-2)?/?$ /NEWNAME/$2 [L,NC,R=302,NE]
Any help appreciated.
2
Answers
With your shown samples please try following .htaccess rules file. We need to use
THE_REQUEST
variable here and also make sure to clear your browser cache before testing your URLs.You are pretty close, you can do like this: