MyBB Community Forums

Full Version: Change URL in all threads - find and replace
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi

I have a big problem.
In mybb we have 5000 treads, and in all treads are there a download link like:

Http://example.com/1/2/filename.zip 

But all should be changed to http://example.com/filename.zip

Is there a simple way or a guide to search all treads and make a find and replace?
I think the best way to achieve it is to run a snippet of PHP + SQL code.
(2019-10-28, 09:50 PM)noyle Wrote: [ -> ]I think the best way to achieve it is to run a snippet of PHP + SQL code.

Is it possible to do the task in phpMyadmin?
(2019-10-28, 09:59 PM)find-us.dk Wrote: [ -> ]
(2019-10-28, 09:50 PM)noyle Wrote: [ -> ]I think the best way to achieve it is to run a snippet of PHP + SQL code.

Is it possible to do the task in phpMyadmin?

Is it just .zip files and attachments? I think MyBB does it all with URL/MONTH/DATE or something like that. I don't think there is really an easy way to achieve this. Also why do you want to do this? You might lose some SEO by altering links.
(2019-10-28, 09:59 PM)find-us.dk Wrote: [ -> ]
(2019-10-28, 09:50 PM)noyle Wrote: [ -> ]I think the best way to achieve it is to run a snippet of PHP + SQL code.

Is it possible to do the task in phpMyadmin?

Don't think so. You need someone to write a script for you. Alternatively you can set a 301 redirect on that URL in htaccess, and just leave the threads as is.
Is your site hosted on a server with terminal access to the operating system?
If so, then you can create a symbolic link for this directory and point to the desired folder.
You can do this as a temporary solution until the URL are really fixed.

BTW, do you really want to put all download files into the root directory, no need for structure!?

[ExiTuS]
Peharps they are downloads from another site and the site changed its directory structure.

Btw, there is no simple way to make a preg_replace with MySQL, you'll have to make a script.
Or export your datas, modify them (notepad++ allows regexp replaces) and re-inject datas.
Maybe OP can try this SQL using MySQL's REPLACE() function, though it's not the most optimal one for either precise manipulation or handling large amount of data record:
UPDATE mybb_posts SET message = REPLACE(message,'http://example.com/1/2/','http://example.com/');

PS, wish someone will write a plugin like WordPress's Better Search Replace https://wordpress.org/plugins/better-search-replace/ .
(2019-10-29, 12:56 PM)noyle Wrote: [ -> ]Maybe OP can try this SQL using MySQL's REPLACE() function, though it's not the most optimal one for either precise manipulation or handling large amount of data record:
UPDATE mybb_posts SET message = REPLACE(message,'http://example.com/1/2/','http://example.com/');

Will work only if /1/2/ is a fixed value, it's rarely like that.
I think @noyle is on the right track. If it were me, I'd make a local copy of my forum, create a PHP script that cycles through every post, uses regex to detect the links that you want to change, fabricates the replacement URL, and then stores that list for use by the next script.

Then create another script that actually replaces the links, by using the find and replace text saved in the list mentioned above.