26

So I cant get an alias working in "/etc/httpd/conf.d/vhosts.conf" which contains all of my virtual hosts:

<VirtualHost *> 
    ServerName example.com
    Alias /ncn /var/www/html/ncn
    DocumentRoot /var/www/html/mjp
</VirtualHost>

I want my alias to work so I can point example.com/ncn to "/var/www/html/ncn".

This works if I have it in "/etc/httpd/conf/httpd.conf" but not my "/etc/httpd/conf.d/vhosts.conf"

Any ideas why? Everything else seems to work i.e. ServerAlias's

Cheers, Peter

ptimson
  • 5,533
  • 8
  • 35
  • 53
  • 7
    Closed? Sure that makes sense, because no programmer ever has to touch a webserver right? How about all of the rest of the "non-programming" questions, [for example](http://stackoverflow.com/questions/4538572/apache-multiple-documentroot)? *Pedant!* – a20 Dec 01 '14 at 00:54
  • Yeah, looks like this should have been posted in serverfault. – Cool Javelin Dec 23 '16 at 19:04

1 Answers1

53

This worked in the end:

<VirtualHost *> 
    ServerName example.com
    DocumentRoot /var/www/html/mjp

    Alias /ncn "/var/www/html/ncn"

    <Directory "/var/www/html/ncn">
        Options Indexes FollowSymLinks MultiViews
        Require all granted
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>
double-beep
  • 5,031
  • 17
  • 33
  • 41
ptimson
  • 5,533
  • 8
  • 35
  • 53
  • So the important option is including all the directives within the VirtualHost directory. – Laith Leo Alobaidy Jul 08 '15 at 07:32
  • 13
    update __2016__: use this inside for recent versions of apache: `Options Indexes FollowSymLinks MultiViews Require all granted` – Flion Nov 07 '16 at 18:22
  • 1
    What happens when ``/var/www/html/ncn`` is outside the root directory, let's say ``ncn`` is inside ``/home/username/``, owned by ``username:username``, obviously ``www-data`` doesn't have access to ``ncn`` now, and say, we don't want to change the ownership of the directory but still give ``www-data`` user access to ``/home/username/ncn``, how do we do that? – quanta Apr 09 '20 at 10:14
  • I created a symlink from my local folder into the /var/www/ folder and was able to access those files. sudo ln -s /media/$USER/Extra/ /var/www/ And then create an "Alias" to /var/www/ as mentioned above. – user5071787 Jun 30 '20 at 06:23
  • @Flion The answer is regarding a conf file. How to achieve it through htaccess file? – Umair Oct 15 '21 at 15:36