Let’s assume you have an Apache Web Server running which hosts several virtual hosts. Again each virtual host has one (!) main domain as soon as multiple (!) alias domains that redirects to the main domain (independently whether the “www” is a prefix of the address or not). So how can you define that scenario in your virtual host’s configuration? Here comes my suggestion:
First of all you have to enable Apache’s rewrite engine. Be sure that the rewrite module has been successfully loaded before.
RewriteEngine On
In the second step use the “RewriteCond” command to define all of your alias domains.
RewriteCond %{HTTP_HOST} ^(www\.)?alias-domain1\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?alias-domain2\.com [NC,OR]After all just define your main domain with the “RewriteRule” command:
RewriteRule ^(.*)$ http://www.main-domain.com$1
Well, the snippet above uses much regex stuff. Please have a look at Apache’s URL Rewriting Guide.







0 Responses to “Redirecting Domains Using Rewrite”