Change URL's from old domain to new domain in all posts

Get help with installation and running phpBB 3.2.x here. Please do not post bug reports, feature requests, or extension related questions here.
Post Reply
User avatar
scootergrisen
Translator
Posts: 216
Joined: Thu Aug 25, 2011 2:25 pm
Contact:

Change URL's from old domain to new domain in all posts

Post by scootergrisen »

My board used to be on another domain.
During that time me and the users have written lots of URL's for that domain which worked since the URL's was pointing to the correct ressources.

Now the board is on another domain.
But the posts are still the same with URL's pointing to the now old domain which i dont have anything to do with anymore.

How do i chance all the URL's in the posts so they point to the new domain instead of the old domain?
Of course i would like to check what is being changed before making the change and not just change all the URL's blindly.
User avatar
warmweer
Jr. Extension Validator
Posts: 5861
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium

Re: Change URL's from old domain to new domain in all posts

Post by warmweer »

scootergrisen wrote:
Wed Oct 16, 2019 2:23 am
How do i chance all the URL's in the posts so they point to the new domain instead of the old domain?
https://stackoverflow.com/questions/118 ... ysql-query
scootergrisen wrote:
Wed Oct 16, 2019 2:23 am
Of course i would like to check what is being changed before making the change and not just change all the URL's blindly.
If you want to check each post individually, then manual editing is the way to go.
If you want to see the generic result of the SQL, then you could execute the SQL on 1 record;
Then there's always a testrun on a copy. (doesn't even have to be a copy of the database, a copy of the table is sufficient).
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.
User avatar
scootergrisen
Translator
Posts: 216
Joined: Thu Aug 25, 2011 2:25 pm
Contact:

Re: Change URL's from old domain to new domain in all posts

Post by scootergrisen »

I would like to see something specific to phpBB.

Maybe a regex something like:

Code: Select all

<[URL|IMG|LINK_TEXT] url="[http|https]://host.domain1
I dont want to just change "host.domain1" to "host.domain2" because that will change some text where i write about the old domain that i dont want changed.
User avatar
P_I
Registered User
Posts: 1336
Joined: Tue Mar 01, 2011 8:35 pm
Location: Staying home - Western Canada
Contact:

Re: Change URL's from old domain to new domain in all posts

Post by P_I »

In a previous phpBB release the procedure was discussed in Changed Domain Name. Change internal links in posts?. I don't know if it still applies in phpBB 3.2.x.

If you are going to attempt any database changes MAKE SURE you have up-to-date and valid backups before proceeding.

I'd even strongly recommend creating a test board on localhost, see Knowledge Base - Transferring Your Board to a New Host or Domain for more details.
Normal people… believe that if it ain’t broke, don’t fix it. Engineers believe that if it ain’t broke, it doesn’t have enough features yet. – Scott Adams
User avatar
Mick
Support Team Member
Support Team Member
Posts: 22919
Joined: Fri Aug 29, 2008 9:49 am
Location: Watching cricket probably.

Re: Change URL's from old domain to new domain in all posts

Post by Mick »

"The more connected we get the more alone we become" - Kyle Broflovski©
User avatar
2600
I've Been Banned!
Posts: 2567
Joined: Fri Nov 14, 2014 5:14 pm
Location: Area-51

Re: Change URL's from old domain to new domain in all posts

Post by 2600 »

What you want to do with keeping a domain that you write about and changing the domain from the old site to the new site is a little hard to do unless you can run a SQL query that specifically matches forums or posts to omit those mentions that shouldn't be changed.

Since I'm SQL dumb and when I changed domain names several times, I just backed up my database and then took the SQL database file, opened it in Notepad ++ and did a search and replace for domain1.com to replace for domain2.com. It did it all in one shot that took 1 second. Then I saved and went into phpMyadmin and uploaded the new database file. This actually worked to my surprise. No issues that I ever saw. Now granted this isn't how you should do this, but it does work. But your requirements don't allow you to do the poor man's Notepad ++ trick since you want to retain some of the old domains.
Morpheus: Unfortunately, no one can be told what The Matrix is. You'll have to see it for yourself.
Hack me.
Consider a canary token.
The nature of my chosen username
:ugeek:
User avatar
warmweer
Jr. Extension Validator
Posts: 5861
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium

Re: Change URL's from old domain to new domain in all posts

Post by warmweer »

scootergrisen wrote:
Sat Oct 19, 2019 4:25 pm
I dont want to just change "host.domain1" to "host.domain2" because that will change some text where i write about the old domain that i dont want changed.
So: what you need to find out is whether the links you don't want changed can be identified or marked in one way or another so that these aren't modified by the search and replace system.
Only you can identify the ones you want to keep.
If that isn't possible then manual editing seems the way to go but I guess that's out of the question.
What John connor proposed is probably the safest way but will take quite some time as you'll still have to review each instance found and decide whether to edit it or not.

Find out first how many instances of the search string there are, to see whether it's feasible. Let's accept there are 100 instances of host.domain1 and you want to keep 10 of those. Then it's feasible using John Connor's method. If that is 1000 instances and 100 to keep then I'ld forget about it and edit them in the board using the edit function when they're encountered (perhaps ask your users to report the posts when they encounter the ones that need editing.
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 4254
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Change URL's from old domain to new domain in all posts

Post by thecoalman »

scootergrisen wrote:
Sat Oct 19, 2019 4:25 pm
Maybe a regex something like:

Code: Select all

<[URL|IMG|LINK_TEXT] url="[http|https]://host.domain1

You can do regex with query (assuming it's supported by your version).

Code: Select all

UPDATE phpbb_posts SET 
post_text = REGEXP_REPLACE
(

post_text, 

'pattern', 

'replacement'
           
)

WHERE `post_id` NOT IN (1,2,3);
Replacement supports placeholders from your pattern. The WHERE clause would skip posts you have identified you want to leave alone.

That said I'm not so sure you can't accomplish this with multiple search and replace if you are just finding sand replacing the domain. You do need to be careful with search and replace, find cat and replace with dog turns catastrophe into dogastrophe. ;) You need a very specific single pattern.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
scootergrisen
Translator
Posts: 216
Joined: Thu Aug 25, 2011 2:25 pm
Contact:

Re: Change URL's from old domain to new domain in all posts

Post by scootergrisen »

Now i did most of them with search and replace from phpmyadmin.
I had to do search and replace like 20 times to make sure i only did it on the correct links (hopefully) and now i got under 100 addresses left to check manually.

I had to do it double (one time for http:// and one time for https://)
And <LINK_TEXT cuts the address with " ... " so its not always easy.
Hope i did not mess up a lot of posts.
User avatar
warmweer
Jr. Extension Validator
Posts: 5861
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium

Re: Change URL's from old domain to new domain in all posts

Post by warmweer »

scootergrisen wrote:
Mon Oct 21, 2019 12:45 am
Hope i did not mess up a lot of posts.
Which I why this should (have) be(en) done on an offline copy.
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 4254
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Change URL's from old domain to new domain in all posts

Post by thecoalman »

scootergrisen wrote:
Mon Oct 21, 2019 12:45 am
Hope i did not mess up a lot of posts.
If you have backup you can can always do partial restore.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
Post Reply

Return to “[3.2.x] Support Forum”