XF 2.2 How to mass change 'http' to 'https' (links in old posts)?

Anatoliy

Well-known member
I discovered that I have about 3k of ancient links in posts on my forum that are 'http' (posted when https era didn't come yet).
What would be the way to convert 'http://' into 'https://'?

I guess I should go to phpmyadmin and execute some code there?
Or maybe there is a button "convert all to https" somewhere in the ACP? 🙏
 
Solution
This query will update post content:
SQL:
UPDATE xf_post SET message = REPLACE(message, 'original_content', 'new_content');

However, you can't just update all URLs to use HTTPS - the site has to support it.

Brogan

XenForo moderator
Staff member
This query will update post content:
SQL:
UPDATE xf_post SET message = REPLACE(message, 'original_content', 'new_content');

However, you can't just update all URLs to use HTTPS - the site has to support it.
 
Solution

Anatoliy

Well-known member
This query will update post content:
SQL:
UPDATE xf_post SET message = REPLACE(message, 'original_content', 'new_content');
Thank you, Brogan!
However, you can't just update all URLs to use HTTPS - the site has to support it.
That's fine, I will go 1 by 1 by the domain name. First will check if it supports https, then will apply your magic code.
So, to avoid the "Help! I ruined my forum!" post further in this thread... )))

Say a have 20 links to http://www.abc.com and it supports https. Would this be the correct code?
SQL:
UPDATE xf_post SET message = REPLACE(message, 'http://www.abc.com', 'https://www.abc.com');

Just want to be sure there are no hidden obstacles like backslashes in front of // or something...
 

Brogan

XenForo moderator
Staff member
That will work - the / don't need any special treatment.

For imgur for example it would be:
SQL:
UPDATE xf_post SET message = REPLACE(message,'http://imgur','https://imgur');

Take a backup of xf_post at least before you make any changes.
 

Anatoliy

Well-known member
That will work - the / don't need any special treatment.

For imgur for example it would be:
SQL:
UPDATE xf_post SET message = REPLACE(message,'http://imgur','https://imgur');
And a dot also doesn't need any special treatment? (I have to ask as nfortunately in your imgur example you didn't include it).

Take a backup of xf_post at least before you make any changes.
aye aye sir! 👨‍🔧
 

Brogan

XenForo moderator
Staff member
And a dot also doesn't need any special treatment? (I have to ask as nfortunately in your imgur example you didn't include it).
No.

I didn't include anything after imgur as it's unlikely there will be any other URLs which begin with that.
However, to be on the safe side, you can include the period -- REPLACE(message,'http://imgur.','https://imgur.'); -- and the TLD if you wish -- REPLACE(message,'http://imgur.com','https://imgur.com');.
 

Mr Lucky

Well-known member
I did this years ago and indeed it works as described. If it is your own domain though, it does not mitigtae the need for .htaccess redirects from http to https (in the event of external links inbound links)
 

Mr Lucky

Well-known member
a lot of links? did you notice any change in your organic search traffic?
No, not then. But i wouldn't expect to. Even I had been using purely the htaccess instead of changing the internal domain links I don't think it would make the slightest difference to Google to be honest. It's more of a tidyness OCD thing.
 
Top