Question

Noob Here.. I have the following folder structure on my Ubuntu Machine

 /var/www/
        /folder1
        /folder2

Now i want to redirect my url xyz.com to folder1 & xyz.com/blog to folder2. I am using the following Vhost Config file

For xyz.com to folder1

  <VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName xyz.com
    ServerAlias www.xyz.com

    DocumentRoot /var/www/folder1
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>
     .......
   </VirtualHost >

And for xyz.com/blog to folder2

   <VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName xyz.com/blog
    ServerAlias www.xyz.com/blog

    DocumentRoot /var/www/folder2
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>

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

When i enter xyz.com in url, it serves me index file from folder1(As expected & correct) but when i enter xyz.com/blog it shows 404:Not found Error

  Not Found

  The requested URL /blog/ was not found on this server.

  Apache/2.2.22 (Ubuntu) Server at socialcosmo.com Port 80

I have spent hours on this and still unable to figure out the problem :( Any help would be greatly appreciated

Was it helpful?

Solution

There's no such thing as a host (domain name) with a path in it. xyz.com/blog is not a valid ServerName.

Delete the second virtual host and add an alias directive to your first one.

Alias /blog /var/www/folder2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top