VirtualHost con htaccess y mod_rewrite

Lo básico para crear un virtualhost con .htaccess habilitado y mod_rewrite. Si lo hacemos en Apache2 creamos un archivo nuevo en /etc/apache2/sites-available/ y le llamamos por ejemplo wiki.7throot:
NameVirtualHost *
<VirtualHost *>
        ServerAdmin     info@7throot.com
        DocumentRoot    /var/www/htdocs/wiki.7throot.com/
        ServerName      wiki.7throot.com

        ErrorLog        /var/www/logs/wiki.7throot-error.log
        CustomLog       /var/www/logs/wiki.7throot-access.log combined

        RewriteEngine   on
</VirtualHost>
Despues del RewriteEngine on irían las RewriteRules dependiendo de lo que queramos modificar, pero si además necesito que ese mod_rewrite lleve implícitos ficheros .htaccess con las reglas simplemente añado ésto:
<Directory /var/www/htdocs/wiki.7throot.com/>
  AllowOverride All
</Directory>
Ojo, hay que repetir la ruta en la directiva Directory. El ejemplo completo podría ser éste:
NameVirtualHost *
<VirtualHost *>
        ServerAdmin     info@7throot.com
        DocumentRoot    /var/www/htdocs/wiki.7throot.com/
        ServerName      wiki.7throot.com

        ErrorLog        /var/www/logs/wiki.7throot-error.log
        CustomLog       /var/www/logs/wiki.7throot-access.log combined

        RewriteEngine   on
        <Directory /var/www/htdocs/wiki.7throot.com/ >
                AllowOverride All
        </Directory>
</VirtualHost>
Una vez tenemos el archivo vamos a habilitar el sitio y reiniciar el apache:
# a2ensite wiki.7throot
# /etc/init.d/apache2 reload

About the author

Óscar
has doubledaddy super powers, father of Hugo and Nico, husband of Marta, *nix user, Djangonaut and open source passionate.