New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
WordPress - MySQL - replace domain for all pdf links in database.
Hello there,
We have a website with a huge number of PDF documents.
All PDFs are moved to a new location (v2.domain.com ) and everything else stays at the original location (domain.com).
How can I update the database to change the domain for all links that contain PDF?
domain.compdf replace with v2.domain.compdf?
We use Ubuntu, I have key help with phpmyadmin.
Is it better to do it via some plugin or via MySQL query?
Can you please help me with query?
I have tried:
- https://stackoverflow.com/questions/2090928/mysql-replace-substring-if-string-ends-in-jpg-gif-or-png
- https://stackoverflow.com/questions/5746035/need-to-search-and-replace-image-path
UPDATE wp_posts
SET post_content = REPLACE(post_content, 'http://domain.com', 'http://v2.domain.com')
WHERE post_content LIKE '%.pdf%';
Regards
Comments
https://wordpress.org/plugins/update-urls/
Try this
This could also work: https://wordpress.org/plugins/better-search-replace/
That one never worked out for me.
UPDATE wp_posts SET guid = REPLACE(guid, 'domain.com', 'v2.domain.com') WHERE post_type = 'attachment' AND post_mime_type = 'application/pdf';
Hm, it worked for me in the past. Ofc, might also search/replace in PHPMyAdmin directly (without the need for any plugin)
https://wordpress.org/plugins/update-urls/
https://wordpress.org/plugins/better-search-replace/
This 2 did not work, i need only to update pdf links, not all links at web site.
Every pdf document have different name.
I will try this
Take backup
mysqldump -u root -p my_db > /var/www/databasebackup/dbbackup.sql
Find/Replace string in backup
sudo sed -i 's|domain.compdf|v2.domain.compdf|g' /var/www/databasebackup/dbbackup.sql
Restore database
mysql -u root -p my_db < /var/www/databasebackup/dbbackup.sql
Just look up the table structure and query the DB. ChatGPT could do it all for you.
Keep a backup in case.
Try to modify this.
Or simply add this to Nginx conf:
Or
You can use
wp-cli
to replace:@Outdoor
Could you provide what output you get from what you try to get a better understanding of what is wrong
@alilet has shown a foolproof option that will most likely work for you btw
I have used this plugin on several occasions and it works correctly.
https://wordpress.org/plugins/better-search-replace/