XF 1.5 How to improve https environment

#1
Dear all,
I have changed the setup of my xenforo website in order to enforce https instead of http.
My forum has around 1 500 000 messages and I can see on a lot of pages any issues related to mixed content with links to http content instead of https.
It is due to hardcoded links in posts and in signatures.
Do you have a solution in order to avoid this issue?
Maybe a SQL script to launch directly through PhpMyAdmin in order to correct the URLs?
Thanks in advance for your help.
David
 
#3
Thank you very much Brogan!
Is it important to setup a secret key for https?
Do you see any other important things to setup in options when you move from http to https?
I hope that Google will appreciate ;-)
Thanks
David
 

Brogan

XenForo moderator
Staff member
#4
Yes, just create a random string for the key.
If you have enabled the image or link proxy, this secret key will ensure that images and links are only proxied if the requests originated at your forum. If you find that links are being accessed via third-party sites, you can change this secret key to expire these links. All links stored on the forum will be automatically updated to use the new secret key.
 

Arty

Well-known member
#6
Create a simple add-on that replaces all http links to your website with https.

How to do that:
1. Enable debug mode by adding this to library/config.php:
Code:
$config['debug'] = true;
2. In admin panel -> add-ons you'll see new button "create add-on". Click it, fill required fields with whatever data you want, keep install/uninstall fields empty.
3. Create PHP file with your replacement script. Name it library/URLReplacer/Listener.php, put this code in that file:
Code:
<?php
class URLReplacer_Listener
{
   public static function templatePostRender($templateName, &$content, array &$containerData, XenForo_Template_Abstract $template)
   {
       $replacements = array(
           '"http://www.yourdomain.com'   => '"https://www.yourdomain.com',
           '"http://yourdomain.com'   => '"https://yourdomain.com'
       );
       $content = strtr($content, $replacements);
   }
}
Replace yourdomain.com with your domain name

4. In admin panel click Development -> Code Event Listeners -> Create New Code Event Listener, use the following data:
Listen to event: template_post_render
Execute callback (class): URLReplacer_Listener
Execute callback (method): templatePostRender
Add-on: select your add-on
Click save

That's it. You wrote a simple add-on that replaces URLs in all forum output. Open library/config.php again, remove line you've added in step 1.
 

Brogan

XenForo moderator
Staff member
#7
Surely it would be simpler and more efficient to run a single query?
Code:
UPDATE xf_post SET message = REPLACE(message, 'http://domain.com', 'https://domain.com');
 
#9
Hi both,
Thanks for your ideas.
I think I will choose the easiest way... direct SQL in PHPmyadmin. :)
Do you think it is a good idea to do that for SEO?
Thanks
David
 
Top