Forum Moderators: phranque
http://www.mysite.com/dir/index.php?p=21&x=123456789
http://www.mysite.com/dir/index.php?p=21
http://www.mysite.com/dir/index.php?p=26
http://www.mysite.com/dir/index.php?p=28&x=13456&y=789456
http://www.myothersite.com/index.html
RewriteEngine on
RewriteRule ^dir/index\.php\?cPath=2[168].*$ http://www.myothersite.com/index.html [L,R=302]
RewriteEngine on
rewritecond %{REQUEST_URI} ^.*index\.php.*$
RewriteCond %{QUERY_STRING} ^cPath=2[168]$
RewriteRule ^.*$ http://www.myothersite.com/index.html [L,R=302]
index.html. The canonical URL for the site root ends in a trailing slash. REQUEST_URI line is redundant if you make the main RewriteRule pattern ^([^/]+/)*index\.php$ here. This will test for request for index file in any folder or in root. ^cPath=2[168]$ pattern in place with both start and end anchoring, the cPath parameter must be the ONLY parameter in the request. If you want other parameters to be present and the request still be redirected use (^|&)cPath=2[168](&|$) instead.
RewriteEngine on
RewriteCond %{QUERY_STRING} (^|&)cPath=2[136](&|$)
RewriteRule ^([^/]+/)*index\.php$ http://www.myothersite.com/ [L,R=302] example.com/index.php?cPath=nn here. Is there any possibility that anyone will request example.com/?cPath=nn from your site? The code does not redirect those requests, but should do. To fix that use: ^([^/]+/)*(index\.php)?$ instead.
Yes. It's very simple and something that I nearly always forget to do - only discovering the problem on the first live test.
Add a question mark to the end of the target URL. This clears the query string.
Is there any possibility that anyone will request example.com/?cPath=nn from your site?
p= or cPath= as you used both in the original question. Likewise the numbers were 21, 26, 28 in the original question and the later code had 21, 23, 26 instead.