I would like to redirect a virtual host on my server to another domain, which is running on HTTPS. I also would like to only show the original url, hence using the P flag for proxy. Here is the current configuration :
RewriteEngine on
SSLProxyEngine on
RewriteCond %{HTTP_HOST} ^subdomain1\.domain1\.ext1$ [NC]
RewriteRule ^(.*) https://subdomain2.domain2.ext2$1 [L,R,P]
Should I generate a certificate on domain1 with certbot? What webroot should I associate? Should I include the one from domain2?
Currently, I have this in the error.log:
[Wed Jun 27 09:13:42.011549 2018] [ssl:error] [pid 19805] [remote IP2:443] AH01961: SSL Proxy requested for domain1.ext1:80 but not enabled [Hint: SSLProxyEngine]
[Wed Jun 27 09:13:42.011734 2018] [proxy:error] [pid 19805] AH00961: HTTPS: failed to enable ssl support for IP2:443 (subdomain2.domain2.ext2)
However SSLProxyEngine
is set.
Finally, the best solution was to use mod_proxy instead of mod-rewrite.
The http version (redirecting to https)
<VirtualHost *:80>
ServerName domain1.ext1
ServerAlias subdomain1.domain1.ext1
SSLProxyEngine on
ProxyPass / https://subdomain2.domain2.ext2/
ProxyPassReverse / https://subdomain2.domain2.ext2/
ProxyPreserveHost Off
RewriteEngine on
RewriteCond %{SERVER_NAME} =subdomain1.domain1.ext1
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>
The https version
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName domain1.ext1
ServerAlias subdomain1.domain1.ext1
SSLProxyEngine on
ProxyPass / https://subdomain2.domain2.ext2/
ProxyPassReverse / https://subdomain2.domain2.ext2/
ProxyPreserveHost Off
SSLCertificateFile /etc/letsencrypt/live/subdomain1.domain1.ext1/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/subdomain1.domain1.ext1/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>