Redirect to a subfolder in Apache virtual host file

ojs picture ojs · Sep 27, 2013 · Viewed 47.1k times · Source

I have Joomla installed on a webserver running Ubuntu Server 12.04. The Joomla folder is located at /var/www/cms/.

My vhost file at /etc/apache2/sites-enabled/default has the following content:

<VirtualHost *:80>
    ServerName domain.com/
    Redirect permanent / https://domain.com/
</VirtualHost>

<VirtualHost *:443>
    ServerAdmin webmaster@localhost
    ServerName domain.com:443

    DocumentRoot /var/www/cms
    <Directory />
        Options FollowSymLinks
        AllowOverride All
    </Directory>
    <Directory /var/www/cms>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>

    (...)
</VirtualHost> 

At the moment, all the requests to domain.com and anything entered after that like domain.com/example gets directed and processed by Joomla which either redirects to a proper page or returns a custom 404 error. This all works.

Now, I would like to filter all the requests that go to domain.com/subfolder before they get processed by Joomla and redirect them to /var/www/subfolder (instead of my root folder at /var/www/cms/).

I believe the file in /etc/apache2/sites-enabled/default (seen above) is the right place to define such a redirect, however I have not been able to figure out at what position and how to achieve this.

Answer

Vincenzo Petrucci picture Vincenzo Petrucci · Sep 27, 2013

You should add to your configuration:

Alias /subfolder /var/www/subfolder
<Directory /var/www/subfolder>
    Order allow,deny
    allow from all
</Directory>

and fit the configuration between "Directory" to your needs.

See the Apache documentation to have more informations.