HTTPS subdomains

Using a single web hosting account to host multiple sites

HTTPS subdomains

Postby S.A » Wed Nov 07, 2007 12:56 pm

Hi,

I manage a server with many accounts that need to be accessed through HTTPS. Rather than purchasing an SSL certificate for each domain, I have a wildcard SSL certificate installed at *.example.com. I need some sort of mod_rewrite directive to point sub-subdomains of secure.example.com to the correct directories on the server. For example, I want https://account1.secure.example.com/index.html to point to /home/account1/public_html/index.html.

I tried adding this to .htaccess under example.com's directory:
Code: Select all
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.secure\.example\.com
RewriteRule ^(.*)$  /home/%1/public_html$1

However, for HTTPS requests, it causes a 500 error, and for HTTP requests, it just serves the content from example.com. Can anyone help?
S.A
 
Posts: 4
Joined: Wed Nov 07, 2007 12:44 pm

Postby richardk » Wed Nov 07, 2007 1:19 pm

You will need access to the httpd.conf file, mod_rewrite cannot rewrite outside the current (example.com's) document root. One work around would be to create Symbolic Links from secure.example.com/account1 to /home/account1/public_html.

You can use mod_vhost_alias which was designed for this.

Or you can try this mod_rewrite (in the httpd.conf file, example.con's <VirtualHost>)
Code: Select all
ewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.secure\.example\.com$ [NC]
RewriteRule ^(/.*)$  /home/%2/public_html$1 [QSA,PT,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby S.A » Wed Nov 07, 2007 1:29 pm

Thanks for the quick response. I tried adding the mod_rewrite you suggested to httpd.conf, and it looks to be closer to what I need, but now I'm getting a 404 error:
The requested URL /home/account1/public_html/ was not found on this server.

Symbolic links would be useful, but I have so many domains that it would take a long time to create them, and it would be a hassle to keep them updated when new accounts are created or deleted (which happens often). Also, I've attempted to use mod_vhost_alias in the past, but I wasn't having much luck because I kept getting "connection refused" errors.

Also, I'm not sure if this matters, but I forgot to mention that I'm using Apache 1.3.x.
S.A
 
Posts: 4
Joined: Wed Nov 07, 2007 12:44 pm

Postby richardk » Wed Nov 07, 2007 1:37 pm

I tried adding the mod_rewrite you suggested to httpd.conf, and it looks to be closer to what I need, but now I'm getting a 404 error:

That looks like it's still rewriting relative to the document root.

Also, I've attempted to use mod_vhost_alias in the past, but I wasn't having much luck because I kept getting "connection refused" errors.

I don't see how mod_vhost_alias could cause that error. Try
Code: Select all
<VirtualHost *:443>
  ServerName secure.example.com
  ServerAlias *.secure.example.com

  VirtualDocumentRoot /home/%-4+/public_html
</VirtualHost>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby S.A » Wed Nov 07, 2007 2:04 pm

Thanks again for the help.

richardk wrote:That looks like it's still rewriting relative to the document root.

Is there some sort of configuration setting to change that?

I don't see how mod_vhost_alias could cause that error.

I tried it again, and I see that the problem is that, when restarting Apache, it looks like it's starting, but isn't (maybe it crashed?). I don't see anything in error_log saying why Apache isn't working correctly, but maybe I'm looking in the wrong place.
S.A
 
Posts: 4
Joined: Wed Nov 07, 2007 12:44 pm

Postby richardk » Wed Nov 07, 2007 2:32 pm

Is there a LoadModule and an AddModule line for mod_vhost_alias? Does Apache start if you comment out VirtualDocumentRoot?

If Apache doesn't start it can't write to it's error log.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby S.A » Thu Nov 08, 2007 10:26 am

Thanks, I checked for mod_vhost_alias and saw that it wasn't even installed on the server. Instead, I went back to the mod_rewrite and removed the PT flag, and now everything works great. Thanks again for the help!
S.A
 
Posts: 4
Joined: Wed Nov 07, 2007 12:44 pm

Postby richardk » Fri Nov 09, 2007 2:45 pm

I went back to the mod_rewrite and removed the PT flag, and now everything works great.

Thanks for posting that, i'll (hopefully) remember for next time.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 15 guests

cron