I have the following configuration with 2 virtual hosts on my Apache: www.domain.com and res.domain.com. The first one is open the second is limited to registred users.
<VirtualHost *:80>
ServerName www.domain.com
DocumentRoot /website/www
<Directory "/website/www">
Options FollowSymLinks
AllowOverride All
RewriteEngine On
RewriteCond %{REQUEST_URI} !api/dispatch\.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^api/.*$ api/dispatch.php [L,QSA]
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName res.domain.com
DocumentRoot /website/res
<Directory "/website/res">
Options FollowSymLinks
AllowOverride All
AuthType Basic
AuthUserFile /website/res/users.sec
<Limit GET POST>
Require valid-user
</Limit>
</Directory>
</VirtualHost>
I would like to serve all the calls http://res.domain.com/api/* exactly as if they were http://www.domain.com/api/*. No authentication and same behavior...
Important: I don't want my users see a redirect...
I need help because I tried so many things but no success.
EDIT 1 The idea here is to have a part of the web site ('api' in this case) that is accessible freely (= with no authentication) from all the virtual hosts without replicating the code.
Folders:
/website /www /img /api /css /... /res /...
I have tried combining Alias, RewriteRule and Directory... ex:
<VirtualHost *:80>
ServerName www.domain.com
DocumentRoot /website/www
<Directory "/website/www">
Options FollowSymLinks
AllowOverride All
RewriteEngine On
RewriteCond %{REQUEST_URI} !api/dispatch\.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^api/.*$ api/dispatch.php [L,QSA]
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName res.domain.com
DocumentRoot /website/res
Alias /api /website/www/api
<Directory "/website/www/api">
Options FollowSymLinks
AllowOverride All
Satisfy Any
Allow from all
RewriteEngine On
RewriteCond %{REQUEST_URI} !dispatch\.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ dispatch.php [L,QSA]
</Directory>
<Directory "/website/res">
Options FollowSymLinks
AllowOverride All
AuthType Basic
AuthUserFile /website/res/users.sec
<Limit GET POST>
Require valid-user
</Limit>
</Directory>
</VirtualHost>
In this case, the call to http://res.domain.com/api/... is still restricted with basic authentication.