In order to match the query string (ie. page_id=123
part) you need a RewriteCond
directive and the QUERY_STRING
server variable (from mod_rewrite). Try something like the following in the /abc/.htaccess
file (ie. in the subdirectory you want to redirect from):
RewriteEngine On
RewriteCond %{QUERY_STRING} ^page_id=123
RewriteRule ^$ /xyz/newindividualpage/ [R=302,L]
(Change the 302
to 301
when you are sure it's working OK. 302
(temporary) redirects aren't cached by the browser, so makes testing easier.)
This redirects any URL within the /abc
subdirectory that has a query string that starts page_id=123
(as per your example).
Alternatively, if you prefer to only use the .htaccess
file in the document root, then add the following to the top of the .htaccess
file (at least before any other mod_rewrite directives) in the root directory:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^page_id=123
RewriteRule ^abc/?$ /xyz/newindividualpage/ [R=301,L]
The RewriteEngine
directive only needs to appear once in the file. It can appear anywhere in the file, although it is more logical if it appears at the top. (It doesn't matter if it occurs more than once, it's just unnecessary.)