What I am trying to achieve is the following: I want to have numerous subdomains such as abc.domain.com redirect to a url such as www.domain.com/something?subdomain=abc

Since I am redirecting to a fully qualified domain, I needed to use a reverse proxy to avoid the change of the URL in the browser. (using the [P] Flag and turning on the mod_proxy module and some other modules)

This is my DNS setup

*.domain.com.   14400    A

This is my virtual host configuration for apache

    ServerName www.domain.com
    ServerAlias *.lionite.com
    DocumentRoot /var/www/html
    ErrorLog /var/www/logs
    UseCanonicalName off

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/images
RewriteCond   %{HTTP_HOST}      !^www\.domain\.com$
RewriteRule   ^(.+)     %{HTTP_HOST}$1          [C]
RewriteRule   ^([^.]+)\.domain\.com(.*) http://www.domain.com/something?subdomain=$1 [P,L]

This setup is working fine (Let me know if you think you can improve it of course).

My main problem is when I am trying to setup https://

This is my virtual host configuration for apache

ServerName www.domain.com:443
ServerAlias *.domain.com
DocumentRoot /var/www/html

SSLEngine on
SSLProtocol all -SSLv2
SSLCertificateFile /etc/httpd/conf.d/cert/server.crt
SSLCertificateKeyFile /etc/httpd/conf.d/cert/server.key

<Directory "/var/www/cgi-bin">
    SSLOptions +StdEnvVars

SetEnvIf User-Agent ".*MSIE.*" \
         nokeepalive ssl-unclean-shutdown \
         downgrade-1.0 force-response-1.0

CustomLog logs/ssl_request_log \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/images
    RewriteCond   %{HTTPS_HOST}      !^www\.domain\.com$
    RewriteRule   ^(.+)     %{HTTPS_HOST}$1          [C]
    RewriteRule   ^([^.]+)\.domain\.com(.*) https://www.domain.com/something?subdomain=$1 [P,L]


Whenever I call https://abc.domain.com - the response I am getting is the homepage but no matter what I am appending to the end of the subdomain, I will get the same response. It's like the rewrite isn't responding well.

Any help would be appreciated, or if you could share how you'd setup reverse proxy, rewrite, wildcard subdomain and SSL all together



As SSL is a transport protocol and it wraps http, you can't have SSL vhosts. This means that HTTP_HOST is not meaningful ... try replacing HTTPS_HOST with SERVER_NAME

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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