MyBB Community Forums

Full Version: force image url to use https
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I want to change all image (http) links  to (https) so it will not break the ssl.

Can it be done with custom mycode or needed to edit the mybb parser ?


Why switch to HTTPS for SEO?

I'm a Data Scientist from Nepal. For me, SEO is very important.

Following the latest Google Algorithm Update, https is must for the website security. So, I've been working since past month to increase my security of my site. But, the MyBB didn't officially support SSL/TLS by default (at the time of writing). Recently, I had used Cloudflare's flexible SSL. Everything switched to https except external images/links.

I hope this problem will get fixed soon.
I use a plugin which I'm willing to share although it will require a bit of editing. Most importantly, it requires a camo server (So you need to be running on your own server, or figure out how to deploy it on Heroku - there appears to be a nice button for that) for the actual image proxying.

Camo can be acquired from here: https://github.com/atmos/camo
That also covers the basic setup/config, I'm willing to help more if you need it.

Then there is the MyBB plugin, you can grab it here: https://gist.github.com/Cameron-D/a685a83196650991875c
I was planning on making a more full-featured HTTPS-related plugin but ended up getting to lazy and just making something that fits my needs.

The plugin forces some common (to my board, yours probably differ) images hosts to use HTTPS if I know they already support it, the rest get rewritten through camo.
It also replaces all your board URLs with protocol-relative ones, if you are running both HTTP and HTTPS (I currently am while I fix any migration-related bugs).

In the plugin you'll need to edit:
YOURBOARDURL with your board URL.
YOURCAMOPROXYADDRESS with the address of your camo proxy.

Add a new MyBB setting through you ACP with the identifier of "hmac_key" and the value set to be the same as CAMO_KEY (Or you can hardcode it into the plugin, replacing $mybb->settings["hmac_key"] with your key).
is it possible to convert all my external urls starting with "http://" or "https://" into " //" so i dont need to run a proxy scripts. (i use shared hosting)

Example: <img src="http://hello.com/pic.jpg" /> into <img src="//hello.com/pic.jpg">

If sm1 uses http version of url in avatar,link,signature etc then it also creates problem,

I think https support should be added by default in mybb as lots of websites/forums are migrating to secured protocol (https)
(2014-11-13, 06:55 AM)RoyalBird Wrote: [ -> ]is it possible to convert all my external urls starting with "http://" or "https://" into " //" so i dont need to run a proxy scripts. (i use shared hosting)

Example: <img src="http://hello.com/pic.jpg" /> into <img src="//hello.com/pic.jpg">

If sm1 uses http version of url in avatar,link,signature etc then it also creates problem,

I think https support should be added by default in mybb as lots of websites/forums are migrating to secured protocol (https)

Use this plugin - http://mods.mybb.com/view/ssl-switcher

then change the Board URL to //yoursitename in in General Configuration.

You now have support for both https and http, basically you set all urls in templates to //linkiewinkie and the plugin converts it depending on the url state, if https then it adds https Big Grin

I did not explain it too well but its what worked for me.
you can try use something this

$plugins->add_hook("parse_message", "image_relative");
function image_relative($message) {
 // Assign pattern and replace values.
 $pattern = array('#src="http:(.*?)#si');

 $replace = array('src="$1');

 while(preg_match($pattern[0], $message))
 {
 $message = preg_replace($pattern, $replace, $message);
 }

 return $message;
} 
(2014-11-13, 01:32 PM)dmpops22 Wrote: [ -> ]Use this plugin - http://mods.mybb.com/view/ssl-switcher

then change the Board URL to //yoursitename in in General Configuration.

You now have support for both https and http, basically you set all urls in templates to //linkiewinkie and the plugin converts it depending on the url state, if https then it adds https Big Grin

I did not explain it too well but its what worked for me.

I dont think that will change external url into https

(2014-11-14, 02:43 AM)martec Wrote: [ -> ]you can try use something this


$plugins->add_hook("parse_message", "image_relative");
function image_relative($message) {
 // Assign pattern and replace values.
 $pattern = array('#src="http:(.*?)#si');

 $replace = array('src="$1');

 while(preg_match($pattern[0], $message))
 {
 $message = preg_replace($pattern, $replace, $message);
 }

 return $message;
} 

Where should i put that code and does it change the external images urls into https ??
(2014-11-13, 06:55 AM)RoyalBird Wrote: [ -> ]is it possible to convert all my external urls starting with "http://" or "https://" into " //" so i dont need to run a proxy scripts. (i use shared hosting)

Example: <img src="http://hello.com/pic.jpg" /> into <img src="//hello.com/pic.jpg">

If sm1 uses http version of url in avatar,link,signature etc then it also creates problem,

I think https support should be added by default in mybb as lots of websites/forums are migrating to secured protocol (https)

You can't do that for every site. Not every site supports HTTPS, and some sites have a different host name or path structure for HTTPS than for HTTP (eg. have a hostname secure.domain.com instead of www.domain.com).
Example : <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js">

Using bare // in urls i think is suppoted by both https and http so that we dont have issues of mixed content while using SSL connection.

Quote:If someone post the link of http://google.com/pic.jpg can it be converted into <img src="//google.com/pic.jpg" /> by mybb parser or plugins so that it wont break the SSL.
(2014-11-15, 05:14 AM)RoyalBird Wrote: [ -> ]Example : <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js">

Using bare // in urls i think is suppoted by both https and http so that we dont have issues of mixed content while using SSL connection.




If someone post the link of [b]http://google.com/pic.jpg[/b] can it be converted into <img src="[b]//google.com/pic.jpg[/b]" /> by mybb parser or plugins so that it wont break the SSL.

my code change http:// to //


in notepad++ copy code below

<?php 
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
 die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

// Plugin info
function imgrelative_info ()
{
 return array(
 "name" => "imgrelative",
 "description" => "",
 "website" => "",
 "author" => "",
 "authorsite" => "",
 "version" => "",
 "guid" => "",
 "compatibility" => "18*"
 );
}

$plugins->add_hook("parse_message", "image_relative");
function image_relative($message) {
 // Assign pattern and replace values.
 $pattern = array('#src="http:(.*?)#si');

 $replace = array('src="$1');

 while(preg_match($pattern[0], $message))
 {
 $message = preg_replace($pattern, $replace, $message);
 }

 return $message;
}

?>

and rename to imgrelative.php and put to plugin folder, and active in ACP
That won't work for everything though, not all sites will support https which is why you need to run a proxy.
Pages: 1 2