1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.5 conditional if is="https" - use in templates?

Discussion in 'XenForo Questions and Support' started by Sperber, Oct 4, 2015.

  1. Sperber

    Sperber Active Member

    For Zend it´s possible to have that sorted out by something like

    if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
        echo "something";
    } else {
        echo "something other";
    Is there an option to use something similiar in templates? How could this be done?
  2. Chris D

    Chris D XenForo Developer Staff Member

    <xen:if is="{$requestPaths.protocol} == 'https'">
    <xen:else />
        something other
  3. Sperber

    Sperber Active Member

    Argh,.. sometimes I hate it to have asked. Thanks, Chris ;)
  4. Sperber

    Sperber Active Member

    @Chris D , since it seems you are more experienced regarding xenforo on https - may I ask for your help once again ? Unfortunal this goes over my head and the forums are only showing the well known htaccess redirects, which won´t fit here.

    we switched to https, Google is allowed to index those sites. The remaining problem now is, that we need unregistered members to be redirected the other way, from https to http. I know, some may ask 'Why the heck you wanna do that?'. That´s needed because our premium ad-partner can´t deliever https only and else we get a) mixed content and security warnings in the users browsers and b) we only show this advertiser now on http - and we need the money.

    Of course, I could redirect the whole traffic via htaccess

    RewriteCond %{SERVER_PORT} ^443$
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
    to force ssl, but that would redirect all and not just guests. For that I need xf to sort them out via
    <xen:if is="{$requestPaths.protocol} == 'https' AND !{$visitor.user_id}">
    replace protocol portion 'https' with 'http' and redirect
    Honestly I have no idea how I could put the redirect rule into proper xf syntax - or wether this function could be possible in the first place.

    Any help (even good ideas) would be really appreciated.

  5. Chris D

    Chris D XenForo Developer Staff Member

    If I'm being brutally honest, I would either be exploring other advertisers or sticking with HTTP only. Any solution to this problem is bordering on "nasty".

    One such solution:

    <xen:if is="{$requestPaths.protocol} == 'https' AND !{$visitor.user_id}">
        <meta http-equiv="refresh" content="0;URL='http://www.example.com{$requestPaths.requestUri}'" />
    It should work... but... o_O
    Sperber likes this.
  6. Sperber

    Sperber Active Member

    Thanks for taking the time to answer, Chris. I really appreciate that.

    Yes, I see - not the elegant way (but in hundred years I wouldn´t have spared a thought on the meta refresh..!). But what comes up my mind now is, that robots would be redirected also and I guess BigG hates that ;) Do you know a variable like {$visitor.robot} so this could be utilized to add a 'AND !{$visitor.robot}' here? By now I never came across a variable for them. Even when the function seems to be wired and hardcoded somewhere, I wasn´t able to find a hint in the documentation.
    For sure. Unfortunal we´ll have to stick with them for 8 months from now on. As it´s the #6th of our nationwide advertising agencies, nothing but disappointing.
    Last edited: Oct 6, 2015
  7. Jake B.

    Jake B. Well-Known Member

    Just to clarify a bit, don't do this if you're using an htaccess redirect, it will rip the fabric of the space time continuum, or just infinitely redirect. Probably more of the latter than the former.
    Sperber likes this.
  8. Sperber

    Sperber Active Member

    Thanks Jake,

    see your point. As this loop can´t be avoided I guess we have to do it vice versa. Disallowing SE to index https and to redirect {$visitor.user_id} to https instead. The more I think about, the more I´m convinced it can´t be done the other way. Heck..

Share This Page