0

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.

1 Answers1

0

Instead of using proxy pass we can have fine grain control over it using RewriteCond and RewriteRule and use the [P] mod_proxy flag

RewriteCond %{HTTP_HOST} ^(monitor.whatfix.com)$ [NC]
RewriteCond %{REQUEST_URI} =/api
RewriteRule (.*) http://othersite.com/api [P,L]

If the request is from sub domain then i am rewriting it to the other site.