• 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?

Sperber

Active member
#1
For Zend it´s possible to have that sorted out by something like

Code:
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?
 

Chris D

XenForo developer
Staff member
#2
Code:
<xen:if is="{$requestPaths.protocol} == 'https'">
    something
<xen:else />
    something other
</xen:if>
 

Sperber

Active member
#4
@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.

Situation:
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

Code:
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
Code:
<xen:if is="{$requestPaths.protocol} == 'https' AND !{$visitor.user_id}">
replace protocol portion 'https' with 'http' and redirect
</xen:if>
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.

Thanks,
Sperber.
 

Chris D

XenForo developer
Staff member
#5
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:

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

Sperber

Active member
#6
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.
If I'm being brutally honest, I would either be exploring other advertisers or sticking with HTTP only.
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:

Sperber

Active member
#8
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..