Subdomains auto redirect
on domain.tld we have different websites under default, f.e.
www.domain.tld/default/site_one , www.domain.tld/default/site_two, ......
We want a rewrite rule so that site_one.domain.tld will be redirected to the site www.domain.tld and the same for site_two and any other (new) site.
In stead of using virtual hosts we can use the follwing apache redirect rule which needs to be placed in the documenr root, in the file .htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(((?!www).)+).maxdata.ovh$ [NC]
RewriteRule "(.*)" "http://www.maxdata.ovh/default/%1" [NC]
</IfModule>
The condition is that the subdomian is not equal to 'www', if so the redirect will take place and traffic will be redirected to www.domain.tld/default/subdomain
Apache2 (onder Ubuntu Server)
Check met phpinfo() in php file of mod_rewrite aan staat (ctr-f in phpinfo() page)
sudo a2enmod rewrite
sudo service apache2 restart
PHP Info
<?php
phpinfo();
?>