Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

How can I forward www.sub.domain.com to //sub.domain.com

This is all in 1 virtual host

<VirtualHost *:443>

    Include /etc/apache2/vhosts.d/ssl.conf.include

    DocumentRoot /scripts/htdocs/domain-live

    ServerName sub.domain.com

    ErrorLog /var/log/apache2/smartdox-wellpoint_error
    CustomLog /var/log/apache2/smartdox-wellpoint_access combined

    <Directory /scripts/htdocs/smartdox-live>
        Options -Indexes FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all


<VirtualHost *:433>
    Include /etc/apache2/vhosts.d/ssl.conf.include

    ServerName www.sub.domain.com

    RewriteEngine On
    Redirect 303 / https://sub.domain.com
share|improve this question

5 Answers 5

up vote 0 down vote accepted


ServerAlias *.sub.domain.com

to the vhost-config.

share|improve this answer

As others have mentioned... you can just accept the other domain as an alias... or you can setup a rewrite rule that will redirect to the correct site name with the alias.

RewriteCond %{REMOTE_HOST}  =www.sub.domain.com
RewriteRule ^/(.*) https://sub.domain.com/$1

If you really don't want the alias... add a 2nd virtualhost with the rewrite rules... and set the servername to the www.sub.domain.com

share|improve this answer

Try putting

ServerAlias www.sub.domain.com

after ServerName

share|improve this answer
I use that on another virtual host, so I can't implement it here since I'm looking for a specific solution. –  Webnet Dec 12 '11 at 18:25
Could you add ServerAlias www.sub.domain.com? This way it will only see that domain and not act as a wild card. –  kobaltz Dec 12 '11 at 19:41

Similar to TheCompWiz, I suggest just accepting the conections by adding the ServerAlias.

Instead of redirecting a specific domain, I suggest you select a canonical domain and then use this rewrite rule.

RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://www.example.com/$1 [L,R]

This rule says if the host does not match www.example.com redirect to www.example.com.

So in your case you would match against your sub-domain.

share|improve this answer

If you want to do such a redirect, probably the best thing would be to set up an additional VirtualHost like this and place a rewrite in it like this:

<VirtualHost *:443>
    ServerName www.sub.domain.com
    Redirect permanent / https://sub.domain.com

To redirect all http requests to https you can use another VirtualHost like this: ServerName sub.domain.com ServerAlias www.sub.domain.com

Redirect permanent / https://sub.domain.com

This requires the Apache module mod_alias to be installed and enabled.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.