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

2
  • 7
    Closed? Sure that makes sense, because no programmer ever has to touch a webserver right? </sarcasm> How about all of the rest of the "non-programming" questions, for example? Pedant!
    – a20
    Dec 1, 2014 at 0:54
  • Yeah, looks like this should have been posted in serverfault. Dec 23, 2016 at 19:04

1 Answer 1

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>
5
  • So the important option is including all the directives within the VirtualHost directory. Jul 8, 2015 at 7:32
  • 13
    update 2016: use this inside <Directory> for recent versions of apache: Options Indexes FollowSymLinks MultiViews Require all granted
    – Flion
    Nov 7, 2016 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 9, 2020 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/<abc> /var/www/<xyz> And then create an "Alias" to /var/www/<xyz> as mentioned above. Jun 30, 2020 at 6:23
  • @Flion The answer is regarding a conf file. How to achieve it through htaccess file?
    – Umair
    Oct 15, 2021 at 15:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.