What is the best way to transparently rewrite a URL over an SSL connection with Apache 2.2?

Apache 2 does not natively support multiple name-based virtual hosts for an SSL connection and I have heard that mod_rewrite can help with this. I would like to do something like this:

I have set up the server so that the sites can be accessed by

but I would like to have this as

How do I set it up so that the Rewrite rule will rewrite to, but without displaying the rewrite on the client's address bar (i.e. the client will still just see, all over https?


There is apaches mod_rewrite, or you could setup apache to direct to path/to/ on the server

<VirtualHost *>
DocumentRoot /home/httpd/htdocs/subdomain/
+2  A: 

Unless your SSL certificate is the "wildcard" or multi-site kind, then I don't think this will work. The rewrite will display in the browser and the name in the address bar must be valid against the certificate, or your users will see a security error (which they can always accept and continue, but that doesn't sound like what you'd like).

More here.

Terry Lorber
+2  A: 

Configure a single VirtualHost to serve both and (making it the only *:443 VirtualHost achieves this). You can then use mod_rewrite to adjust the URI for requests to

<VirtualHost *:443>

    RewriteEngine on
    RewriteCond %{SERVER_NAME}
    RewriteRule !/dbadmin(.*)$ /dbadmin$1

Your SSL certificate will need to be valid for both and It can be a wildcard certificate as mentioned by Terry Lorber, or you can use the subjectAltName field to add additional host names.

If you're having trouble, first set it up on <VirtualHost *> and check that it works without SSL. The SSL connection and certificate is a separate layer of complexity that you can set up after the URI rewriting is working.

Ted Percival