Koozali.org: home of the SME Server

Obsolete Releases => SME 7.x Contribs => Topic started by: mikalof on April 26, 2011, 11:36:10 AM

Title: Redirect ibay to use https
Post by: mikalof on April 26, 2011, 11:36:10 AM
Hello, I found this howto, http://wiki.contribs.org/Https_redirection (http://wiki.contribs.org/Https_redirection), that states it will force https redirection of an ibay but I cannot get it working. The only thing it does is deny http, still allowing https.
If this Howto is wrong then is there another way of forcing https (redirect from http) in an ibay?
Title: Re: Redirect ibay to use https
Post by: imcintyre on April 26, 2011, 12:11:27 PM
Perhaps wording is not correct; isn't this what you wanted, "deny http, https still working"?
Title: Re: Redirect ibay to use https
Post by: mikalof on April 26, 2011, 12:18:18 PM
Perhaps wording is not correct; isn't this what you wanted, "deny http, https still working"?
To be even more clear, I want redirection of http to https, per ibay. Not just deny http.
The Howto claims to redirect but not for me.
Title: Re: Redirect ibay to use https
Post by: johnp on April 26, 2011, 01:25:06 PM
Did you try Ray Mitchell's method? It's the first link at the top of that how to.
Title: Re: Redirect ibay to use https
Post by: mikalof on April 26, 2011, 01:55:00 PM
Did you try Ray Mitchell's method? It's the first link at the top of that how to.
Aren't they both Ray's? However I used the later one since the earlier seemed quite old. They also seem to be set up to work quite differently. I could give the older version a try but would prefer the later because it has a db setting for enabling/disabling per ibay.
Title: Re: Redirect ibay to use https
Post by: johnp on April 26, 2011, 01:58:27 PM
I don't think the later was done by Ray. From what I can tell, the later only denys access like you said.
Title: Re: Redirect ibay to use https
Post by: mikalof on April 26, 2011, 02:12:53 PM
I don't think the later was done by Ray. From what I can tell, the later only denys access like you said.


Tried the earlier version and it works! Thanks for "redirecting" me :-)

Well, if the later version isn't even supposed to redirect then why is it in a howto called "Https redirection"? I guess it should be called "Deny plain http" or "Require SSL" and posted separately.
Title: Re: Redirect ibay to use https
Post by: Stefano on April 26, 2011, 02:14:44 PM

Tried the earlier version and it works! Thanks for "redirecting" me :-)

Well, if the later version isn't even supposed to redirect then why is it in a howto called "Https redirection"? I guess it should be called "Deny plain http" or "Require SSL" and posted separately.

if something is wrong with the documentation please open a bug or, better, register and edit the wiki page
Title: Re: Redirect ibay to use https
Post by: johnp on April 26, 2011, 02:29:24 PM
Stefano, I was going to suggest that :)

Either way, I hope the OP found it a learning experience.
Title: Redirect ibay to use https
Post by: mikalof on April 26, 2011, 03:35:50 PM
Filed bug http://bugs.contribs.org/show_bug.cgi?id=6604 (http://bugs.contribs.org/show_bug.cgi?id=6604).
Title: Re: Redirect ibay to use https
Post by: johnp on April 27, 2011, 02:59:37 AM
If you want to have something the can be controlled with a db setting, somthing like this should work

Code: [Select]
{
    use esmith::AccountsDB;
    my $adb = esmith::AccountsDB->open_ro();
    $OUT = "";

    foreach my $ibay ($adb->ibays)
    {
      my %properties = $ibay->props;
      my $key = $ibay->key;
      if ($properties{'HTTPSredir'})
      {
          if ($properties{'HTTPSredir'} eq 'on')
          {
             if ($port ne "443")
             {
                $OUT .= "    ## Redirect Web Address to Secure Address\n";
                $OUT .= "    RewriteEngine on\n";
                $OUT .= "    RewriteRule ^/$key(/.*|\$) https://%{HTTP_HOST}/$key\$1 [L,R]\n";
                $OUT .= "    ## End Of Redirect\n";
              }
          }
       }
    }
}


Slightly modified Ray's code. It should need only one 60redir-ibay custom fragment.
db accounts setprop ibayname HTTPSredir on
Title: Re: Redirect ibay to use https
Post by: mikalof on April 28, 2011, 01:51:55 PM
This one works even better! I can see the RewriteRule is a bit different, it apparently redirects also to subdirs and files that are referenced, not only to ibay root.

Is this The RewriteRule that completely "translates" the http request to a https? At least not yet has anyone complained about old http links not working...
Title: Re: Redirect ibay to use https
Post by: johnp on April 28, 2011, 08:43:12 PM
Yes, I modified the rewrite rule yesterday morning to account for lower levels. Since writing code is not my forte, I took most if it from the 2 fragments discussed in the howto.

I believe the logic is sound and from my limited testing, I have found no problem.

Ray's code can also be used for non ibay custom-templates fragments.
Title: Re: Redirect ibay to use https
Post by: johnp on April 29, 2011, 01:15:53 AM
FWIW, If you want to get the same results using Ray's code, change the RewriteRule from:

Code: [Select]
RewriteRule ^/ibayname https://%{HTTP_HOST}/ibayname
to

Code: [Select]
RewriteRule ^/ibayname(/.*|$) https://%{HTTP_HOST}/ibayname$1  [L,R]

BTW, thanks for bringing this issue up as I had encounter it before but never took the time to look at it deeper as I already used Ray's code for my needs. It's nice to be able to give back to the community. :)

One other thing, I believe the current proper way to restart httpd is:

Code: [Select]
sv t httpd-e-smith