Reputation: 23
Can anyone tell me how to redirect if incoming URL contains certain text as having real trouble with this..
For instance:
RedirectMatch 301 /files/9453041/batch-BiDA http://secondsite.com (THIS WORKS)
RedirectMatch 301 /?load=/files/9453041/batch-BiDA http://secondsite.com (THIS DOESNT WORK)
Only the first of the above two redirects work, not sure why but the second containing the /?load= doesnt redirect. Can someone either tell me what i need change on the second line for it to work?
Or perhaps I was thinking if it couldnt be made to work if it would be possible to redirect every incoming url that has "mysite.com/?load=/whatever/whatever" to "mysite.com/whatever/whatever"?
Many thanks for any help...
Upvotes: 1
Views: 93
Reputation: 143906
In order to match query strings (everything after the ?
), you need to match against the %{QUERY_STRING}
variable using a rewrite condition:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^load=/files/9453041/batch-BiDA
RewriteRule ^/?$ http://secondsite.com/ [L,R=301]
You can also use the [OR]
:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^load=/files/9453041/batch-BiDA [OR]
RewriteCond %{QUERY_STRING} ^load=/files/35356441/batch-546A
RewriteRule ^/?$ http://secondsite.com/ [L,R=301]
etc.
But if you don't care what follows the /files/
part, just match the numebrs:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^load=/files/[0-9]+/batch-[0-9A-Za-z]+
RewriteRule ^/?$ http://secondsite.com/ [L,R=301]
Upvotes: 0