I have two applications configured on one apache (eg. example.com and test.net). Rewrite rules for those apps are the same (so in config file for domain example.com I've got this rules, and the same rules in conf file for test.net domain)
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}
And it almost works ok, except for one case - when I request in webwrowser https://www.test.net.
In this only case apache redirets to https://www.test.net but displays content of https://www.example.com (not content of https://www.test.net as it should). Request www.test.net works ok. And https:// www.example.com also works ok.
And here's whole Virtual Host config for test.net (config for example.com is analogical):
<VirtualHost *:80>
ServerName test.net
DocumentRoot /var/www/test/web/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/test/web/>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/test_error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/test_access.log combined
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}
</VirtualHost>
And Virtual Host file for example.com
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/example/>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example_error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/example_access.log combined
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
I've got also ofcourse config file for ssl settings (eg. ssl certs), but there's no redirect rules.
How to configure rewrite rules for this two applications so that it work properly?
Any suggestions very appreciated! So far I don't know where my mistake is.
Thanks in advance,
Kind regards!
I think you are missing
ServerAlias www.test.com
andServerAlias www.example.com
in your VirtualHost configs and that causes you these problems.