3

I'd like to redirect a subdomain to a user directory.

So I've tried this config, but it seems redirect to the root folder.

<VirtualHost *:80>
    ServerName epnet.fr
    ServerAlias *.epnet.fr

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^([a-z0-9-]+)\.epnet\.fr
    RewriteCond /home/%1/apps/ -d
    RewriteRule ^(.*) /%1/$1 [L]
    <Directory /home>
        Options Includes FollowSymlinks
        AllowOverride All
        Order allow,deny
        Allow from All
    </Directory>
</VirtualHost>

For example, I've a user 'tiste', I'd like to redirect tiste.epnet.fr to /home/tiste/apps/ and then, any pages of the website which are on apps/ will be accessible tiste.epnet.fr/index.php

Thanks !

2 Answers 2

1

Apache comes with a very convenient module for this called mod_userdir which would make this much easier than using just rewrites. (There's a good tutorial for it here.) Specifically to combine this with virtual hosts, this is documented here.

0

You need to use DocumentRoot

<VirtualHost *:80>
    ServerName epnet.fr
    ServerAlias *.epnet.fr

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^([a-z0-9-]+)\.epnet\.fr
    RewriteCond /home/%1/apps/ -d
    RewriteRule ^(.*) /%1/$1 [L]
    DocumentRoot /var/www/whatfolderyouwant
</VirtualHost>

Make sure the folder you are creating has the correct permissions:

 sudo chmod -R 755 /var/www/whatfolderyouwant

And then finally make sure you activate the host using the command:

 sudo a2ensite epnet.fr

This tutorial was very helpful to me when learning to setup virtual hosts on apache2: https://www.digitalocean.com/community/articles/how-to-set-up-apache-virtual-hosts-on-ubuntu-12-04-lts

1
  • I agree with you, but I can't set a documentroot cause it depends on the subdomain name... Here is the issue I'm stuck in.
    – tiste
    May 28, 2013 at 14:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .