Rewriter script for changing to https

Started by Sono, January 18, 2024, 01:24:57 PM

Previous topic - Next topic

Sono

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.

Sesquipedalian

#1
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"
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Sono

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?

Arantor

The % is a wildcard, you definitely need it.
Holder of controversial views, all of which my own.


Sono

Is the query correct anyway like that? I don't want to mess up the table.

Arantor

Looks fine to me, if in doubt take a backup first.
Holder of controversial views, all of which my own.


Aleksi "Lex" Kilpinen

Or, just take a backup first anyway. It's a good idea when ever making changes directly in the database. Just in case.
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Sesquipedalian

#7
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.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Kindred

Also, if the target url is not actually https, you will still have problems
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Sono

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.

Kindred

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.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Sono

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.

Aleksi "Lex" Kilpinen

External Image Proxy 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.
Slava
Ukraini!
"Before you allow people access to your forum, especially in an administrative position, you must be aware that that person can seriously damage your forum. Therefore, you should only allow people that you trust, implicitly, to have such access." -Douglas

How you can help SMF

Sesquipedalian

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.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Sono

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...

Coon_Dog

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]

Sesquipedalian

I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Steve

Since the OP has been here yesterday with no further input on this issue, marking solved.
My pet rock is not feeling well. I think it's stoned.

Advertisement: