2

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
    </Directory>

</VirtualHost>

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

    ServerName www.sub.domain.com

    RewriteEngine On
    Redirect 303 / https://sub.domain.com
</VirtualHost>
0

5 Answers 5

0

Add

ServerAlias *.sub.domain.com

to the vhost-config.

0

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

0

Try putting

ServerAlias www.sub.domain.com

after ServerName

2
  • I use that on another virtual host, so I can't implement it here since I'm looking for a specific solution.
    – Ben
    Dec 12, 2011 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, 2011 at 19:41
0

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.

0

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
</VirtualHost>

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .