Posts: 71
Threads: 12
Joined: Apr 2014
Reputation:
6
2014-11-10, 06:30 AM
(This post was last modified: 2021-01-09, 04:04 AM by RoyalBird. Edited 2 times in total.)
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.
Posts: 506
Threads: 5
Joined: Dec 2009
Reputation:
47
2014-11-10, 09:43 AM
(This post was last modified: 2014-11-10, 09:44 AM by Cameron:D.
Edit Reason: lol forgot URL
)
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).
Posts: 71
Threads: 12
Joined: Apr 2014
Reputation:
6
2014-11-13, 06:55 AM
(This post was last modified: 2017-04-17, 11:45 AM by RoyalBird.)
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)
Posts: 140
Threads: 46
Joined: Sep 2014
Reputation:
1
2014-11-13, 01:32 PM
(This post was last modified: 2014-11-13, 01:32 PM by dmpops22.)
(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
I did not explain it too well but its what worked for me.
Posts: 2,530
Threads: 124
Joined: Jul 2011
Reputation:
293
2014-11-14, 02:43 AM
(This post was last modified: 2014-11-14, 02:44 AM by martec.)
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;
}
Posts: 71
Threads: 12
Joined: Apr 2014
Reputation:
6
2014-11-14, 10:34 AM
(This post was last modified: 2017-04-17, 11:45 AM by RoyalBird.)
(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 Big Grin](https://community.mybb.com/images/smilies/biggrin.gif)
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 ??
Posts: 2,064
Threads: 33
Joined: Nov 2005
Reputation:
37
2014-11-14, 07:35 PM
(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).
Posts: 71
Threads: 12
Joined: Apr 2014
Reputation:
6
2014-11-15, 05:14 AM
(This post was last modified: 2017-04-17, 11:46 AM by RoyalBird.)
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.
Posts: 2,530
Threads: 124
Joined: Jul 2011
Reputation:
293
2014-11-15, 05:18 AM
(This post was last modified: 2014-11-15, 05:41 AM by martec.)
(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
Posts: 506
Threads: 5
Joined: Dec 2009
Reputation:
47
2014-11-15, 12:38 PM
That won't work for everything though, not all sites will support https which is why you need to run a proxy.
|