I want to redirect my api calls from sub domain to main domain. My api server is in example.com. Request url is http://foo.example.com/api?service=work&action=all_work, but my file system calls should come through.
<VirtualHost *:80>
ServerName example.com
ServerAlias foo.example.com
RewriteEngine On
<Proxy *>
Order Allow,Deny
Allow from all
</Proxy>
<Location /api>
ProxyPass http://othersite.com/api retry=0
SetOutputFilter DEFLATE
</Location>
DocumentRoot /var/www/example
RewriteCond %{HTTP_HOST} ^(foo.example.com)$ [NC]
RewriteCond %{REQUEST_URI} =/
RewriteRule (.*) /var/www/example/index.html [L]
RewriteCond %{HTTP_HOST} ^(foo.example.com)$ [NC]
RewriteCond %{REQUEST_URI} !=/
RewriteRule (.*) /var/www/example/$1 [L]
</VirtualHost>
But I am getting 404 on the browser.
Вместо использования прокси-прохода мы можем иметь точный контроль над ним с помощью RewriteCond и RewriteRule и использовать флаг [P] mod_proxy
RewriteCond %{HTTP_HOST} ^(monitor.whatfix.com)$ [NC]
RewriteCond %{REQUEST_URI} =/api
RewriteRule (.*) http://othersite.com/api [P,L]
Если запрос поступает из поддомена, я переписываю его на другой сайт.