Report this

What is the reason for this report?

How to Configure Alias Properly When Rewrite Engine is ON in Apache2 virtual host .conf file

Posted on November 26, 2019

Hi, I am trying to add Alias to directory that is outside my current document root, So the alias would take the matching urls starting with /business to a separate project’s production build folder (/dist).

There is no error, may be because I am using FallbackResource /index.html in my configuration. my apache version is 2.4.39

Can anyone please suggest what i can do to make it work?

The following is my virtual host config file:

<VirtualHost *:80>
        ServerAdmin dewand60@gmail.com
        ServerName app.careerki.com
        ServerAlias www.app.careerki.com

        DocumentRoot /var/www/app.careerki.com/public_html/my-careerki-pwa/dist

        Alias /business /var/www/app.careerki.com/public_html/my-careerki-pwa/dist-dashboard


        <Directory /var/www/app.careerki.com/public_html/my-careerki-pwa/dist/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

        <Directory /var/www/app.careerki.com/public_html/my-careerki-pwa/dist-dashboard/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>


        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        FallbackResource /index.html
        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.app.careerki.com [OR]
RewriteCond %{SERVER_NAME} =app.careerki.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>


From Apache2.4 docs about mod_alias I tried to dig a little deeper, but could not make a complete understanding out of it. Can someone please suggest me in a right direction?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

I quickly tested this with my site and it seems to work:

https://bobbyiliev.com/apache2-alias-test/

So I believe that your setup is correct. What I could suggest is making sure that the permissions for your /var/www/app.careerki.com/public_html/my-careerki-pwa/dist-dashboard directory are correct and that your Apache user has read/write access.

Also I would recommend checking both your Apache error and access logs:

tail -100 /var/log/apache2/error.log
tail -100 //var/log/apache2/access.log

Let me know how it goes! Regards, Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.