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: 213
Joined: Thu Aug 25, 2011 2:25 pm
Contact:

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

Post by scootergrisen » Wed Oct 16, 2019 2:23 am

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
Registered User
Posts: 3027
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

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

Post by warmweer » Wed Oct 16, 2019 6:52 am

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).
The year is 2192. The British Prime Minister visits Brussels to ask for an extension of the Brexit deadline. No one remembers where this tradition originated, but every year it attracts many tourists from all over the world.

User avatar
scootergrisen
Translator
Posts: 213
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 » Sat Oct 19, 2019 4:25 pm

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: 942
Joined: Tue Mar 01, 2011 8:35 pm
Location: Calgary
Contact:

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

Post by P_I » Sat Oct 19, 2019 4:41 pm

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: 21679
Joined: Fri Aug 29, 2008 9:49 am
Location: Cardiff

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

Post by Mick » Sun Oct 20, 2019 9:04 am

"The more connected we get the more alone we become" - Kyle Broflovski

User avatar
John connor
Registered User
Posts: 2306
Joined: Fri Nov 14, 2014 5:14 pm
Location: U S Of A
Name: Aaron
Contact:

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

Post by John connor » Sun Oct 20, 2019 5:57 pm

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.

User avatar
warmweer
Registered User
Posts: 3027
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

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

Post by warmweer » Sun Oct 20, 2019 9:25 pm

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.
The year is 2192. The British Prime Minister visits Brussels to ask for an extension of the Brexit deadline. No one remembers where this tradition originated, but every year it attracts many tourists from all over the world.

User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 3352
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 » Sun Oct 20, 2019 10:43 pm

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: 213
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 » Mon Oct 21, 2019 12:45 am

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
Registered User
Posts: 3027
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

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

Post by warmweer » Mon Oct 21, 2019 9:47 am

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.
The year is 2192. The British Prime Minister visits Brussels to ask for an extension of the Brexit deadline. No one remembers where this tradition originated, but every year it attracts many tourists from all over the world.

User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 3352
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 » Wed Oct 23, 2019 5:16 am

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”