Redirect subdomains to bar one
So I configured Amazon EC2 and registered multiple domains with 123-reg , I configured my Apache VirtualHost. But now I'm going to need to set up multiple subdomains (eg kitty .example.com). But these will be just a few, and I would like the rest of the subdomain wild cards to go to the base like this:
kitty .example.com -> kitty .example.com
BUT
* .example.com -> example.com
currently my DNS with 123-reg looks like this:
www A 198.168.0.0
kitten A 198.168.0.0
* A 198.168.0.0
and my Apache httpd.conf :
<VirtualHost *:80>
DocumentRoot "/var/www/example.com"
ServerName example.com
ServerAlias example.com
<Directory "/var/www/example.com">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/kitten.example.com"
ServerName kitten.example.com
ServerAlias kitten.example.com
<Directory "/var/www/kitten.example.com">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
so how do I redirect all these wildcard subdomains to my base domain?
source to share
Create a virtual host directive that does not specify ServerName or ServerAlias. This will catch all virtual hosts on that IP (you define all IPs on port 80) that do not map to any other virtual host specification.
<VirtualHost *:80>
DocumentRoot /www/default
...
</VirtualHost>
http://httpd.apache.org/docs/2.2/vhosts/examples.html#default
However, if you want to send 301 HTTP headers (permanently redirected), you will need to use mod_rewrite or something similar:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
How to configure Apache mod_rewrite to redirect all but one subfolder is one good example .. needs to be modified to suit your needs if the first option is not sufficient for your needs.
source to share