Score:0

Redirect to other ip but the same query whit Apache mod_rewrite

cn flag

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??

djdomi avatar
za flag
it is unclear to me what you want to Archiv. however if you just want to catch the resource from a other destination, a reverse proxy could make this for you
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.