My question is similar to How to do redirect the URL of site but I want to do the opposite. And there is a further challenge or two I cannot understand yet.
Our setup is a Magento 2.3.3 store running on a dedicated (not shared) Linux host. We have full root access and can edit all files as needed. The httpd server is Apache 2.4.41.
Upon advice received recently, we followed this procedure:
Modify docroot to improve security | Magento 2 Developer Documentation
Now the Magento site is served at https://www.example.com/ and it is working correctly. The Magento DocumentRoot is /var/www/html/magento2/pub/
. All is good for that step. But we cannot reconcile that step with the next steps we need to accomplish.
We will be installing WordPress at /var/www/html/wordpress/
. And we will have Question2Answer at /var/www/html/q2a/
.
We need to accomplish the following:
- Magento store landing page served at https://www.example.com/shop
- WordPress blog page served at served at https://www.example.com
- Question2Answer landing page served at https://www.example.com/qa
I know about Apache Alias directives and reviewed this answer but the following approach does not meet our goals:
<IfModule alias_module>
Alias /shop /var/www/html/magento2/pub/
</IfModule>
While the URI https://www.example.com/shop works, the problem is that https://www.example.com also serves the Magento site. We want the WordPress blog to be served at https://www.example.com.
How can we accomplish our goal with Magento and our two other virtual hosts (all at the same domain www.example.com)?
All pages are served via HTTPS exclusively using a Let's Encrypt certificate. Here are the current virtual host files (only Magento is installed so far).
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/html/magento2/pub/"
ServerName www.example.com
Redirect permanent / https://www.example.com
</VirtualHost>
<IfModule alias_module>
Alias /shop /var/www/html/magento2/pub
</IfModule>
<Directory "/var/www/html/magento2/pub/">
AllowOverRide None
Include /var/www/html/magento2/pub/.htaccess
</directory>
<Directory "/var/www/html/magento2/pub/errors">
AllowOverRide None
Include /var/www/html/magento2/pub/errors/.htaccess
</directory>
<Directory "/var/www/html/magento2/pub/media">
AllowOverRide None
Include /var/www/html/magento2/pub/media/.htaccess
</directory>
<Directory "/var/www/html/magento2/pub/media/customer">
AllowOverRide None
Include /var/www/html/magento2/pub/media/customer/.htaccess
</directory>
<Directory "/var/www/html/magento2/pub/media/downloadable">
AllowOverRide None
Include /var/www/html/magento2/pub/media/downloadable/.htaccess
</directory>
<Directory "/var/www/html/magento2/pub/media/import">
AllowOverRide None
Include /var/www/html/magento2/pub/media/import/.htaccess
</directory>
<Directory "/var/www/html/magento2/pub/media/theme_customization">
AllowOverRide None
Include /var/www/html/magento2/pub/media/theme_customization/.htaccess
</directory>
<Directory "/var/www/html/magento2/pub/static">
AllowOverRide None
Include /var/www/html/magento2/pub/static/.htaccess
</directory>
And for HTTPS:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin [email protected]
DocumentRoot "/var/www/html/magento2/pub/"
ServerName example.com
ServerAlias www.example.com
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite HIGH:!aNULL:!MD5:!3DES:!CAMELLIA:!AES128
</VirtualHost>
</IfModule>