I have a rewrite condition that rewrites /myPage.php?myQueryVar=foo-aRandomString
to /myNewPage/foo-aRandomString
. I only want this to apply in instances where there is a hyphen in the query value therefore I have some conditions in place as seen below:
RewriteCond %{QUERY_STRING} (^|&)myQueryVar=foo-(.*)($|&)
RewriteCond %{THE_REQUEST} ^GET\ /myPage\.php\?myQueryVar=([^\s&]+) [NC]
RewriteRule ^myPage\.php$ /myNewPage/%1? [R=301,L]
I'd like to add another rule exception allowing /myPage.php?myQueryVar=bar-aRandomString
. Currently I've had to simply cloine the above code and use it again but changing foo
to bar
as sen below. Is there a cleaner way of doing this without having to have multiple line of near identical code? Thank you.
RewriteCond %{QUERY_STRING} (^|&)myQueryVar=bar-(.*)($|&)
RewriteCond %{THE_REQUEST} ^GET\ /myPage\.php\?myQueryVar=([^\s&]+) [NC]
RewriteRule ^myPage\.php$ /myNewPage/%1? [R=301,L]