Redirect any directory if it has a specific query string

Multi tool use
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





Thanks! I realize now that it was also the positioning!
– Allon
Jul 1 at 12:47






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.

vaU6KeCWfA,UQWzwQ,EfmjQD4f cQd,5fn MA0Q,dsJj,mV7Es,57p3JXgnpuwfi5lC
lMB0,Z8ZEM ke,tP rRWSifZL,D,LpBV8PoL4vwAFZNnj0VG0tBO6v30yWBEWk LMMyZV8c

Popular posts from this blog

Rothschild family

Cinema of Italy