Question

I have web site on domain.com which is located at /var/www/main

I also have started another web site which I want to be on url domain.com/a/b But the actual file location is /var/www/main/a/b/c

Problem is that I want the users to use url domain.com/a/b and get files from /var/www/main/a/b/c

So I've found domains conf file at /etc/apache2/sites-available/domain.com.conf

It had only this

<virtualhost *:80>
    ServerName domain.com
    DocumentRoot /var/www/main
</virtualhost>

Now after reading different topics about it I've tried to add this so now my domain.com.conf file looks like this

<virtualhost *:80>
    ServerName domain.com
    DocumentRoot /var/www/main
</virtualhost>

<virtualhost *:80>
    ServerName domain.com
    ServerPath /a/b/
    DocumentRoot /var/www/main/a/b/c
    RewriteEngine On
    RewriteRule ^(/a/b/.*) /var/www/main/a/b/c
    # ...
</virtualhost>

But this does not work at all. What am I doing wrong ?

Was it helpful?

Solution

No need for Rewrite Rules. Just set up an alias in /etc/apache2/sites-available/domain.com.conf :

<virtualhost *:80>
    ServerName domain.com
    DocumentRoot /var/www/main
    Alias /a/b /var/www/main/a/b/c
</virtualhost>

Then restart apache :

$ sudo service apache2 restart
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top