I have to redirect the request that a Apache web server receives, using the user_agent to filter.
The idea is that if the user_agent is "Mozilla/5.0 (Macintosh; Intel Mac OS X 12_2_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15" then the proxy have to redirect the request to a machine with ip 192.168.1.40 but if the user agent is not that it have to show the main page.
I have the next code to redirect to the correct machine:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} "=Mozilla/5.0 (Macintosh; Intel Mac OS X 12_2_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.2 Safari/605.1.15"
RewriteRule ^/(.*)$ http://192.168.1.40:443/$1 [L,R=302]
But I have a problem. When I redirect to 192.168.1.40 I need to also add the query string so if the request is http://192.168.2.11/thisisthequery then I need to redirect it to http://192.168.1.40/thisisthequery not just http://192.168.1.40
I've tried the next
RewriteRule ^/(.*)$ http://192.168.1.40:443/%{QUERY_STRING}$1 [L,R=302]
But it doesn't work, how can I do that??
IMPORTANT
The query doesn't exist in the proxy so if I request http://192.168.2.11/thisisthequery I think it isn't even trying to redirect because the response is a Bad request (443). So, how can I redirect before the proxy return the 443 message??