1

Basically my question is exactly this: redirecting www.subdomain.example.com to subdomain.example.com

We give all of our users a myusername.ourdomain.com link, the issue is when someone attempts to visit www.myusername.ourdomain.com our wildcard ssl gets broken and often the server will throw an error.

So the answer in the link I provided shows how to redirect a single www.apachedefined.mydomain.com I'm wondering how to use the same logic to do www.thiscanbeanything.mydomain.com.

Any help is greatly appreciated.

Community
  • 1
  • 1
Peter
  • 3,144
  • 11
  • 37
  • 56

1 Answers1

5

Try adding these rules to the very top of the htaccess file in your document root for the www.*.mydomain.com vhosts:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ https://%1.mydomain.com/$1 [L,R=301]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • I'm getting the error of: You attempted to reach www.50.mydomain.net, but instead you actually reached a server identifying itself as *.mydomain.net. This may be caused by a misconfiguration on the server or by something more serious. An attacker on your network could be trying to get you to visit a fake (and potentially harmful) version of www.50.mydomain.net --- this is the same error we've always been receiving. – Peter Nov 27 '12 at 18:51
  • @Peter are you redirecting or proxying? – Jon Lin Nov 27 '12 at 18:53
  • It's through a Load Balancer so I'm wondering if that's causing it but now I get an SSL error on initial visit but afterwards all other visits do the redirect. That's odd. I edited my apache config directly instead of the htaccess as htaccess wasn't seeming to change anything. – Peter Nov 27 '12 at 19:01
  • EDIT: Yes the Load balancer is trying to do www.*.mydomain.net before the htaccess rules fire.. but the answer is working. Will mark as complete. – Peter Nov 27 '12 at 19:07