Redirect any directory if it has a specific query string

Multi tool use
Redirect any directory if it has a specific query string
I am trying to redirect all pages with a specific query string to another page.
So many pages have this query string, but the URI's are different.
I want to capture any URI and if it has this query string to redirect it but nothing I am doing is working.
So just to be clear:
http://example.com/?redirectme=1
would redirect to
http://example.com/newpage
while also:
http://example.com/randompage/rtandomsirectory?redirectme=1
would also redirect to
http://example.com/newpage
I am sure there must be 2-3 lines I can put in the htaccess to do this but it is not working.
This is a wordpress site if that should make a difference.
Here is what I have tried:
RewriteCond %{REQUEST_URI} ^/(.+)
RewriteCond %{QUERY_STRING} ^redirectme=1$
RewriteRule ^/?$ http://example.com/? [R=301,L]
and
RewriteCond %{REQUEST_URI} ^/(.+)
RewriteCond %{QUERY_STRING} ^redirectme=1$
RewriteRule (.*) http://example.com/? [R=301,L]
different variations:
RewriteCond %{REQUEST_URI} (.+)
RewriteCond %{QUERY_STRING} ^redirectme=1$
RewriteRule (.*) http://example.com/? [R=301,L]
and for the first line:
RewriteCond %{REQUEST_URI} (.*)
And so on....
Any experts on this here?
Thanks
1 Answer
1
You can use this redirect rule as top rule in your site root directory:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^redirectme=1$ [NC]
RewriteRule ^ /newpage? [R=301,L]
# remaining rules below this line
So did this rule work?
– anubhava
Jul 1 at 13:35
Yes perfectly thanks!
– Allon
Jul 1 at 14:49
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thanks! I realize now that it was also the positioning!
– Allon
Jul 1 at 12:47