You are not logged in.
I just installed a secure certificate on our website, and I'm wondering what the recommended method for working with secure pages with static_root and www_root links in the template is? I was hoping that the site would dynamically switch these links to https when a secure page is requested. Hopefully that makes sense. Let me know if I need to clarify. Any help is appreciated, thanks.
Offline
Call $cms->makeSecure() in your template and it will rewrite images, javascript, and CSS includes so they are served over HTTPS.
Offline
Thanks Tim. I figured there would be something like that available. Would you recommend checking the URL to see if the page is requested securely, and then call $cms->makeSecure() if that's the case?
Offline
Nevermind, I'll probably just call it on pages that I know need to be secure.
Offline
$cms->makeSecure() will automatically redirect to the https:// version of the URL if that page is accessed from http://, so you won't need to check for it.
Offline
I just gave it a try. I was hoping for something that would convert the www_root and static_root references in my templates to https links instead of http links so I don't have insecure content, but it doesn't appear to do that.
Offline
I could just make the resource links in my templates relative links, but then I lose the benefit of using the static_root and www_root shortcodes in my templates.
Offline
Hm, strange -- can you provide me with a link to one of the pages that $cms->makeSecure() was called on? It's possible that the regex is failing for some reason and not rewriting the URIs properly (I'm not very good at regex!).
Offline
I changed to relative links and it worked, but I've put the shortcodes back in for you to check out:
Offline
<?
$cms->makeSecure();
?>
<div class="page">
<? include "../templates/layouts/_topshelf.php" ?>
<div class="row outercontent">
<div class="desktop-full tablet-full mobile-full">
<?
include '../templates/layouts/_breadcrumbs.php';
?>
<div class="content">
<? if ($teaser) { ?>
<blockquote><?=$teaser?></blockquote>
<? } ?>
Content
<div class="margin_m"></div>
</div>
</div>
</div>
</div>
Offline
Hm, very strange -- I manually ran the regex replacements and it properly updated to pull from https://. Not sure what's going on unfortunately.
It occurs in /core/router.php on line 400:
// If we're in HTTPS, make sure all Javascript, images, and CSS are pulling from HTTPS
if ($cms->Secure) {
// Replace CSS includes
$bigtree["content"] = preg_replace_callback('/<link [^>]*href="([^"]*)"/',create_function('$matches','
return str_replace(\'href="http://\',\'href="https://\',$matches[0]);
'),$bigtree["content"]);
// Replace script and image tags.
$bigtree["content"] = str_replace('src="http://','src="https://',$bigtree["content"]);
}
You could check if that condition is being ignored for some reason.
Offline
I'm still on 4.1 by the way. Maybe this code was not included yet? I don't see it in /core/router.php. Any problems with adding it in there on this version?
Offline
That's quite odd, makeSecure has existed since 4.0 and I see it in 4.1 as well here:
https://github.com/bigtreecms/BigTree-C … r.php#L400
Have you done any customizing of the router?
Offline
I don't think I've made any changes to core.
Offline
Can you email me your copy of /core/router.php? Curious what's going on there
Offline
My mistake. It's in there.
Offline
Sent
Offline
For reference, this issue was caused by the existence of a $cms object that I created in another included template file. From what I understand, there is never really a need to manually create the $cms object, as all pages should inherit the $cms class, so I removed the object, and everything is happy.
Offline