Koozali.org: home of the SME Server

Cannot redirect http to https Primary website

Offline mikecoan

  • 9
  • +0/-0
Cannot redirect http to https Primary website
« on: September 21, 2016, 04:44:43 PM »
Greetings

We are running SME Server 9.1 for email and webserver.  Just installed 9.1,as our old email serve had been 7.x.  Everything is working well.  Got a free certificate from Letsencrypt.  People can connect to the web site with either http or https.  If they use http, I would like to redirect then to https, just as what happens when you access webmail.

I found this link
https://wiki.contribs.org/Https_redirection

and followed the instructions.  This was written for SME 7.x I believe.  I tried all three methods indicated. I did not get any error messages, but the redirection does not work.  One thing that seems curious is that after expanding the templates the file /etc/httpd/conf/httpd.conf  does not change.  It is the same size and date as yesterday even though I have expanded the template, run signal-event post-upgrade and rebooted several times.  The instructions in the link indicate to put the custom template in /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts.  I ahve done this even though I don't have Virtual Hosts.  I have also moved it to /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/ and that had no effect.

I am happy to redirect all http traffic to https.  The template suggested in the link is as follows

{
if ($port ne "443")
{
$OUT .= <<'HERE';
# Redirect transmission Address to Secure Address
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
## End Of Redirect
HERE
}
}

Any suggestions for redirecting http to https are appreciated.

Mike

Offline janet

  • ****
  • 4,812
  • +0/-0
Re: Cannot redirect http to https Primary website
« Reply #1 on: September 22, 2016, 02:22:51 AM »
mikecoan

It sounds like your changes did not "take", or as this functionality is now built in to SME server, maybe there is a clash occurring.

Suggested good practice is to NOT use the Primary ibay as it has "fixed" settings & therefore limited control of those.
In the Domains panel in server manager you can redirect Primary to an ibay eg ibay named mymainsite
Move any content in the Primary ibay to the mymainsite ibay (or your name of choice).
Remember (or realise) to put the content in the correct subfolder eg /cgi-bin or /files or /html

Then in server manager ibays panel, select mymainsite & tick the box to enable https for that ibay for all connections.
No need for extra custom templates then
Make sure your remove any custom templates you added, do a expand & then reboot.
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

guest22

Re: Cannot redirect http to https Primary website
« Reply #2 on: September 22, 2016, 02:28:05 AM »
Hi and welcome.

you could try to remove the custom templates and run these commands as root:
Code: [Select]
db accounts setprop Primary SSL enabled
signal-event console-save

Offline mikecoan

  • 9
  • +0/-0
[Solved] Re: Cannot redirect http to https Primary website
« Reply #3 on: September 22, 2016, 02:58:17 AM »
Thank you Janet and RequestedDeletion for your quick replies.  The source of the problem was a typo.  I created the custom template in "template-custom" instead of "templates-custom".  For that reason when I ran expand-template the custom template entry never made it into httpd.conf.  Once I put the custom template into the correct directory it worked fine.

Janet, I will consider what you suggested about not using the Primary ibay.  Thanks for the tip.  Thanks for your suggestion RequestedDeletion.  I didn't try it as I have it working now, but your suggestion is pretty simple.

Mike

Offline DanB35

  • ****
  • 764
  • +0/-0
    • http://www.familybrown.org
Re: Cannot redirect http to https Primary website
« Reply #4 on: September 22, 2016, 03:14:54 AM »
It's probably better to follow RequestedDeletion's suggestion than to use the custom template.  I'm basing this on the idea that using the included feature is going to be better supported than doing something custom on your own.  Though if your template fragment's working, there may not be any real need to change it.
......