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

Posted November 26, 2019 9.1k views
ApacheUbuntu 16.04

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>

        DocumentRoot /var/www/

        Alias /business /var/www/

        <Directory /var/www/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted

        <Directory /var/www/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted

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

RewriteEngine on
RewriteCond %{SERVER_NAME} [OR]
RewriteCond %{SERVER_NAME}
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

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?

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.

Submit an Answer
1 answer


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

So I believe that your setup is correct. What I could suggest is making sure that the permissions for your /var/www/ 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!

  • So the problem i have is this one
    I got a static website react on and an efront on a single server
    and I used the alias and when I try to login I get the 404 error
    Not Found
    The requested URL /learn/start was not found on this server.

    I used alias_mod

    My virtual hosts codes

    <VirtualHost *:80>
    #ErrorLog /PATH/errorlog
    #CustomLog /PATH/access
    log combined
    DocumentRoot /var/www/react-web/build

    Alias /learn “/var/www/efront/www”
    <Directory “/var/www/efront/www”>
    Options Indexes FollowSymLinks MultiViews
    Options FollowSymLinks
    Order allow,deny
    allow from all
    Require all granted