5

I recently enabled Force_SSL on one of my Joomla sites (by enabling "Force SSL" in Global Configuration), but I run into problems with blocked content (non-SSL content) from both Google fonts and several external scripts from JotForm.com (loaded through "http://" in template and content).

For this particular site I solved the problem by going through the code and changing each external http://... reference to https://... or just //..., but my question is:

Could this be solved easier or more efficient by automatically changing http://... to https://... in the source code (with a plugin) or using the .htaccess file?

  • 1
    If the links are to external sites, you would have to use a plugin to fix it before your source code with the http:// link is sent back to the browser. .htaccess file would never see external links. An afterRender plugin should be able to do the trick, but you would have to be careful with standard anchor tag links to sites that don't support https. If you changed those, you could break links. – David Fritsch Aug 11 '14 at 4:28
  • I don't think that within htaccess file you would be able to handle this for the external links. Maybe a plugin that would change all links from "http://..." to "//..." would be your way to go, or just simply code your templates from the beginning with that in mind and link with "//..." to your external files. – FFrewin Aug 11 '14 at 6:47
2

You definitely want to set up a plugin for this. Basically the goal would be to rewrite any http:// or https:// to just //. As a bonus, we can only do this check inside of tags (so it doesn't affect urls just on the page.

A system plugin with this method should do the trick:

public function onAfterRender() {
    $buffer = JResponse::getBody();
    $pattern = '~(<[^>]{0,}["\'])(https?://)~iU';
    $replacement = '$1//';
    $buffer = preg_replace($pattern, $replacement, $buffer);
    JResponse::setBody($buffer);
}

This probably will still catch something that you don't want replaced with just //, but it is a start!

  • Or you could probably configure Regular Labs ReReplacer to do this for you. – Neil Robertson Dec 22 '17 at 3:28
1

You don't need to use the protocol in a js link. You can use // and the correct protocol will be selected for you.

Eg.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

I'd just do a global find / replace in my code and leave it like that, and use //src.js going forward.

  • Yes, I'm aware of the //... option as mentioned in my original question, the question is rather how to change existing links. I think a plugin (as others have suggested) would be a better solution, because a global find/replace in both database and template files is not an easy task. – johanpw Aug 11 '14 at 23:53
  • Just to me, it seems like building a plugin is a lot harder than just using grep, awk etc. to find and replace all instances. But obviously it's your choice. – user101289 Aug 12 '14 at 14:44
  • I would say replacing the code yourself is one approach indeed. But if there's an extension X that does not do this properly, I would say you also need to approach the developer of that extension X for fixing this. It's a bug. – Jisse Reitsma Sep 3 '15 at 15:26
1

There is a great plugin for this made by Yireo https://www.yireo.com/software/joomla-extensions/ssl-redirect

Joomla! can be configured to use SSL. But this does not mean that all your secure pages are actually kept secure. This plugin forces what is actually required: HTTPS or HTTP.

Best of all, the developers are very responsive...which makes a world of difference to me.

  • Hi Joseph, the Yireo plugin redirects website visitors to HTTPS versions of the web pages but does not help with changing the http links in the source code of the website. – Neil Robertson Dec 22 '17 at 3:26
  • 1
    Hi Neil, you can use Regular Labs ReReplacer to perform a find & replace to change the URLs - regularlabs.com/extensions/rereplacer – Joseph Dec 23 '17 at 16:33
  • Exactly @Joseph, I made the same comment under the accepted answer! :) – Neil Robertson Dec 28 '17 at 0:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.