Discussion:
SSL and subdomain redirects
(too old to reply)
lieutdan13
2012-01-27 16:08:49 UTC
Permalink
My server hosts all requests to example.com, i.e. example.com, www.example.com,
customer1.example.com, customer2.example.com, etc. I have an SSL
certificate that is only valid for www.example.com, not even
example.com. I haven't been able to find a good answer to my question,
since it involves rewrites in different cases. Here's what I want to
do:

[code]
if HTTP_HOST == 'example.com'
// All requests for example.com, regardless of SSL, redirect to
SSL www site
redirect to https://www.example.com/theRestOfTheURL
else if HTTP_HOST == 'www.example.com' and SERVER_PORT != 443
// For non-SSL requests to www, redirect to SSL www
redirect to https://www.example.com/theRestOfTheURL
else if SERVER_PORT == 443
// For any other requests that are trying to use SSL, redirect to
non-SSL of the same domain name
redirect to http://HTTP_HOST/theRestOfTheURL

Carry out other RewriteRules I may have in place
[/code]


I would prefer to be able to accomplish this with .htaccess rules. But
if I need to accomplish this with a combination of .htaccess rules AND
Apache configuration changes, I'm ok with that too. Thank you in
advance!
lieutdan13
2012-01-30 19:04:36 UTC
Permalink
My server hosts all requests to example.com, i.e. example.com,www.example.com,
customer1.example.com, customer2.example.com, etc. I have an SSL
certificate that is only valid forwww.example.com, not even
example.com. I haven't been able to find a good answer to my question,
since it involves rewrites in different cases. Here's what I want to
[code]
if HTTP_HOST == 'example.com'
     // All requests for example.com, regardless of SSL, redirect to
SSL www site
     redirect tohttps://www.example.com/theRestOfTheURL
else if HTTP_HOST == 'www.example.com'and SERVER_PORT != 443
     // For non-SSL requests to www, redirect to SSL www
     redirect tohttps://www.example.com/theRestOfTheURL
else if SERVER_PORT == 443
     // For any other requests that are trying to use SSL, redirect to
non-SSL of the same domain name
     redirect tohttp://HTTP_HOST/theRestOfTheURL
Carry out other RewriteRules I may have in place
[/code]
I would prefer to be able to accomplish this with .htaccess rules. But
if I need to accomplish this with a combination of .htaccess rules AND
Apache configuration changes, I'm ok with that too. Thank you in
advance!
Anyone? This is really bothering me. I can't seem to figure out the
right order and combination of rules and conditions.
D. Stussy
2012-01-30 19:28:17 UTC
Permalink
Post by lieutdan13
My server hosts all requests to example.com, i.e.
example.com,www.example.com,
Post by lieutdan13
customer1.example.com, customer2.example.com, etc. I have an SSL
certificate that is only valid forwww.example.com, not even
example.com. I haven't been able to find a good answer to my question,
since it involves rewrites in different cases. Here's what I want to
[code]
if HTTP_HOST == 'example.com'
// All requests for example.com, regardless of SSL, redirect to
SSL www site
redirect tohttps://www.example.com/theRestOfTheURL
else if HTTP_HOST == 'www.example.com'and SERVER_PORT != 443
// For non-SSL requests to www, redirect to SSL www
redirect tohttps://www.example.com/theRestOfTheURL
else if SERVER_PORT == 443
// For any other requests that are trying to use SSL, redirect to
non-SSL of the same domain name
redirect tohttp://HTTP_HOST/theRestOfTheURL
Carry out other RewriteRules I may have in place
[/code]
I would prefer to be able to accomplish this with .htaccess rules. But
if I need to accomplish this with a combination of .htaccess rules AND
Apache configuration changes, I'm ok with that too. Thank you in
advance!
Anyone? This is really bothering me. I can't seem to figure out the
right order and combination of rules and conditions.
-----------

For the non-SSL'ed requests, that's simple. Set up a virtual host on port
80 which redirects everything; e.g.

NameVirtualHost *:80
<VirtualHost *:80>
servername example.com
serveralias *.example.com
rewriteengine on
rewriterule (.*) https://www.example.com$1 [R=301]
</VirtualHost>

<VirtualHost www.example.com:443>
...
lieutdan13
2012-01-31 21:09:12 UTC
Permalink
For the non-SSL'ed requests, that's simple.  Set up a virtual host on port
80 which redirects everything; e.g.
NameVirtualHost *:80
<VirtualHost *:80>
  servername example.com
  serveralias *.example.com
  rewriteengine on
  rewriterule (.*)  https://www.example.com$1 [R=301]
</VirtualHost>
<VirtualHostwww.example.com:443>
...
I don't want to include "serveralias *.example.com".
subdomain1.example.com won't have a valid SSL cert. Only www.example.com
will have a valid certificate. It is not a star cert.
D. Stussy
2012-02-01 03:04:48 UTC
Permalink
For the non-SSL'ed requests, that's simple. Set up a virtual host on port
80 which redirects everything; e.g.
NameVirtualHost *:80
<VirtualHost *:80>
servername example.com
serveralias *.example.com
rewriteengine on
rewriterule (.*) https://www.example.com$1 [R=301]
</VirtualHost>
<VirtualHostwww.example.com:443>
...
I don't want to include "serveralias *.example.com".
subdomain1.example.com won't have a valid SSL cert. Only www.example.com
will have a valid certificate. It is not a star cert.
======
Read it again. "*.example.com" occurs on port 80 only in the above. On
port 80, there is no SSL.

Continue reading on narkive:
Loading...