Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: Sono on January 18, 2024, 01:24:57 PM

Title: Rewriter script for changing to https
Post by: Sono on January 18, 2024, 01:24:57 PM
I want to change my forum to https, but my big problem with this is that I have tons of images posted back in the days when everything was http. Those images are important, valuable stuff, my visitors are searching for them. Isn't there a way to keep them after the switching, that is different than the image proxy stuff? Isn't it possible to run a script that rewrites every "http" text fragment to "https" in the database? Then it would be no problem to display those images at all.
Title: Re: Rewriter script for changing to https
Post by: Sesquipedalian on January 18, 2024, 01:31:11 PM
When you switch to https, just make sure that you enable the image proxy. In addition to proxying external images, turning on that setting also causes SMF to rewrite self-hosted http URLs to https on the fly.

EDIT: To be clear, by "self-hosted" in the paragraph above, I mean any URL that points to the forum's base URL or any subdirectory within it. So if your forum is located at https://www.example.com/forum/index.php, turning on the image proxy will automatically change "http://" to "https://" in any URL that starts with "http://www.example.com/forum"
Title: Re: Rewriter script for changing to https
Post by: Sono on January 29, 2024, 08:00:43 AM
I have found a description for WordPress to rewrite things in a way as I thought about:
https://tonyteaches.tech/phpmyadmin-replace-http-with-https/

Based on this, to make http links in posts replaced to https, as I interpret from this article, all I need to do is launch this query, do I?

UPDATE smf_messages
    SET body = REPLACE(body, 'http:', 'https:')
    WHERE body LIKE '%http%';

I am not sure if I need the % character or not?
Title: Re: Rewriter script for changing to https
Post by: Arantor on January 29, 2024, 08:23:50 AM
The % is a wildcard, you definitely need it.
Title: Re: Rewriter script for changing to https
Post by: Sono on January 29, 2024, 09:08:42 AM
Is the query correct anyway like that? I don't want to mess up the table.
Title: Re: Rewriter script for changing to https
Post by: Arantor on January 29, 2024, 09:58:55 AM
Looks fine to me, if in doubt take a backup first.
Title: Re: Rewriter script for changing to https
Post by: Aleksi "Lex" Kilpinen on January 29, 2024, 10:09:17 AM
Or, just take a backup first anyway. It's a good idea when ever making changes directly in the database. Just in case.
Title: Re: Rewriter script for changing to https
Post by: Sesquipedalian on January 29, 2024, 12:31:50 PM
But again, you do not need to do this. Just turn on SMF's image proxy. It will automatically rewrite your internal HTTP URLs to HTTPS for you.

Also, if you use that SQL query, you will change every HTTP URL to HTTPS. It will not just be the URLs of image files, but rather all URLs. You definitely do not want to do that. Those external URLs may not have working HTTPS versions, which means you will break those links. It is a very bad idea to change the URLs supplied in user-generated content.
Title: Re: Rewriter script for changing to https
Post by: Kindred on January 29, 2024, 12:34:31 PM
Also, if the target url is not actually https, you will still have problems
Title: Re: Rewriter script for changing to https
Post by: Sono on January 30, 2024, 06:14:44 AM
Quote from: Kindred on January 29, 2024, 12:34:31 PMAlso, if the target url is not actually https, you will still have problems

I know but hopefully the third party image hosts solved this issue since then.
Title: Re: Rewriter script for changing to https
Post by: Kindred on January 30, 2024, 06:50:32 AM
Not all of them... and your script literally replaced all URLs, without logic. You don't make changes like that based on "hopefully someone else has done something"

Also -- **SMF** already solved tge issue by adding the image proxy service.
Title: Re: Rewriter script for changing to https
Post by: Sono on January 30, 2024, 07:33:58 AM
My only problem with the image proxy at the moment is that it consumes bandwidth. And you can remember from my other posts that I am having bandwidth issue recently, the recent level is 1TB per 12 days. Until I don't solve that issue I don't want to use image proxy.
Title: Re: Rewriter script for changing to https
Post by: Aleksi "Lex" Kilpinen on January 30, 2024, 09:15:50 AM
External Image Proxy (https://custom.simplemachines.org/index.php?mod=4173) might solve this for you, mind you it does rely on a 3rd party so you add a further dependency in the mix - but as long as it works, it should cut down your bandwidth usage while still keeping the proxy alive.
Title: Re: Rewriter script for changing to https
Post by: Sesquipedalian on January 30, 2024, 01:44:25 PM
Quote from: Sono on January 30, 2024, 07:33:58 AMMy only problem with the image proxy at the moment is that it consumes bandwidth. And you can remember from my other posts that I am having bandwidth issue recently, the recent level is 1TB per 12 days. Until I don't solve that issue I don't want to use image proxy.

The image proxy will only consume a fraction of the bandwidth that your other issue is consuming. Rewriting URLs in posts is a permanent change, whereas your other issue is a temporary problem. Focus your attention on fixing the real problem, and then the image proxy's modest bandwidth usage will become a non-issue.
Title: Re: Rewriter script for changing to https
Post by: Sono on January 30, 2024, 03:30:53 PM
Quote from: Sesquipedalian on January 30, 2024, 01:44:25 PM
Quote from: Sono on January 30, 2024, 07:33:58 AMMy only problem with the image proxy at the moment is that it consumes bandwidth. And you can remember from my other posts that I am having bandwidth issue recently, the recent level is 1TB per 12 days. Until I don't solve that issue I don't want to use image proxy.

The image proxy will only consume a fraction of the bandwidth that your other issue is consuming. Rewriting URLs in posts is a permanent change, whereas your other issue is a temporary problem. Focus your attention on fixing the real problem, and then the image proxy's modest bandwidth usage will become a non-issue.

That is true, I will wait with rewriting then...
Title: Re: Rewriter script for changing to https
Post by: Coon_Dog on February 02, 2024, 08:30:41 AM
Wouldn't rewrite in root directory .htaccess file take care of this?  Redirects all incoming http to https.

Permanent redirection 301 - Temporary redirection 302

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Title: Re: Rewriter script for changing to https
Post by: Sesquipedalian on February 02, 2024, 11:21:10 AM
That's a different problem.
Title: Re: Rewriter script for changing to https
Post by: Steve on March 25, 2024, 10:56:14 AM
Since the OP has been here yesterday with no further input on this issue, marking solved.