0

I purchased an SSL cert for an internal web server and it works only if I use the server's FQDN. Is there a way using a rewrite rule in httpd.conf to accomplish this? I already have two rules, and they are:

RewriteCond %{HTTP_HOST}   !^web2\.internal\.domain\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^/(.*)         https://web2.internal.domain.com/$1 [L,R]

RewriteCond %{HTTP_HOST}   ^web2\.internal\.domain\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^/(.*)         https://web2.internal.domain.com/$1 [L,R]

I use these to force http to https, one for short name and one for FQDN.

Thanks

4
  • It seems that your ultimate goal is for all traffic to this web server to be served at https://web2.internal.domain.com. Is this correct? If so, those two rules can be merged into one and simplified by only checking (a) if the port is 80 or (b) if the domain is not the FQDN. If either one of those is true, redirect to https and the FQDN. Is there any additional complexity I'm missing? Dec 22, 2014 at 1:28
  • @David - Probably splitting hairs, but FQDNs end with a dot. So www. and www.example.com. are both considered fully qualified. In fact, I regularly use it to do things like connect to a server within a private network with https://wiki. and https://wiki.example.com
    – jww
    Dec 22, 2014 at 1:34
  • Agreed that I can simplify the rewrite rules but I cannot get them to work if web2..... is what is entered at the browser. Using http://..... everything works perfectly. Am I missing something? And, thanks for your help. Dec 22, 2014 at 2:48
  • In other words the rewrite rules only work for http to https. The do not work when I use https and the non FQDN. Dec 22, 2014 at 3:19

1 Answer 1

0

Based on your comments, I think the issue is that both of your rules test for SERVER_PORT = 80 and if you're accessing over https that will not match. Here is a single merged rule that should work for your case:

RewriteCond %{HTTP_HOST}   !^web2\.internal\.domain\.com$ [NC,OR]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$         https://web2.internal.domain.com$1 [L,R]

The two conditions check if the site is being accessed either by a different domain, e.g. just "web2", or if it is being accessed on the full domain but over port 80 (not SSL). If either case is true, the user is redirected to https with the full domain.

2
  • David,thanks for the update, however I am really not any closer than before. Here is what works and what does not: web2.internal.domain.com --> redirects to https successfully web2..... --> redirects to https successfully web2..... --> does not redirect to web2.internal.domain.com I do appreciate the shortening of my rewrite rules. If there is any way get the last part to work, I appreciate the help. Dec 24, 2014 at 20:14
  • 1
    I haven't worked with such shortened domains before myself, but if the rule isn't catching the https://web2/ case it would seem that either (a) the rule isn't being reached (I'd add a troubleshooting rule just before that one like redirecting all requests for test.txt to test2.txt and making sure the rule triggers for https://web2/test.txt) or (b) HTTP_HOST actually contains the full domain, either due to the client expanding it in its request (check logs to see if that's happening) or Apache filling in the full domain (not sure what config would do that, but maybe check UseCanonicalName). Dec 24, 2014 at 21:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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