View Full Version : Wildcard SSL: Different Secure Content For Each Subdomain

07-08-2008, 06:59 PM
While it is relatively easy to show different content for each subdomain using the WestHost Site Manager, achieving the same thing with secure content is a bit more difficult. Although the Site Manager does not facilitate this function, it can be done using Apache mod_rewrite by following these three steps.

This tutorial assumes you already have a wildcard SSL certificate installed on your server. If you don't have an SSL certificate, you can test this by generating your own wildcard SSL certificate. See How To Generate A Self-Signed SSL Certificate (http://forums.westhost.com/showthread.php?p=39881). These instructions work for both professional (trusted) and self-signed (untrusted) wildcard SSL certificates.

Add each subdomain using the Site Manager. This is necessary so that the appropriate DNS records are created on the WestHost DNS servers. In this example, I've created a subdomain called account pointing to the directory /var/www/account and another called store pointing to the directory /var/www/store.
Edit the /etc/httpd/conf.d/ssl.conf file. Add code to the end of the file, immediately before the </VirtualHost> line. You'll need change the bold portions of the lines below to suit your subdomains and paths, of course. Note that you'll need a RewriteCond and RewriteRule line for each subdomain you'd like to access securely.

RewriteEngine On

RewriteCond %{HTTP_HOST} account.yourdomain.com
RewriteRule ^(.*)$ /var/www/account/$1

RewriteCond %{HTTP_HOST} store.yourdomain.com
RewriteRule ^(.*)$ /var/www/store/$1
Restart Apache (use the restart function from Site Manager or run apachectl restart from the command line). At this point, you'll be able to see different content when you access each subdomain.

The configuration outlined here will allow both http:// and https:// access. If you only want to allow secure access, see How To Force SSL (http://forums.westhost.com/showthread.php?p=39882).

08-29-2008, 11:26 AM
Hi Nick

This is exactly what I was trying to do and tearing my hair out. Thanks to google and you I now have it running .. hurray. To imagine that I spent a few hours looking for something that finally took me 2 minutes to do ...