Zend certified PHP/Magento developer

How to Change URL of Magento Site After Modifying Apache DocumentRoot?

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:

I know about Apache Alias directives and reviewed this answer but the following approach does not meet our goals:


    Alias /shop     /var/www/html/magento2/pub/
    Alias /shop/    /var/www/html/magento2/pub/

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).


        ServerAdmin webmaster@example.com
        DocumentRoot "/var/www/html/magento2/pub/"



        Alias /shop     /var/www/html/magento2/pub
        Alias /shop/    /var/www/html/magento2/pub



        AllowOverRide None
        Include /var/www/html/magento2/pub/.htaccess



        AllowOverRide None
        Include /var/www/html/magento2/pub/errors/.htaccess



        AllowOverRide None
        Include /var/www/html/magento2/pub/media/.htaccess



        AllowOverRide None
        Include /var/www/html/magento2/pub/media/customer/.htaccess



        AllowOverRide None
        Include /var/www/html/magento2/pub/media/downloadable/.htaccess



        AllowOverRide None
        Include /var/www/html/magento2/pub/media/import/.htaccess



        AllowOverRide None
        Include /var/www/html/magento2/pub/media/theme_customization/.htaccess



        AllowOverRide None
        Include /var/www/html/magento2/pub/static/.htaccess

And for HTTPS:



    ServerAdmin webmaster@example.com
    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