Exit Strategy: How to Leave S3
Without Breaking 50,000 Image Links
Moving away from S3 after years of use is not as simple as copying files to a new destination. Tens of thousands of image URLs are embedded in post content, stored in the database, cached in CDN, and referenced by sitemaps and external links. This guide covers the complete migration without a single broken image.
Updated 2026
Complete Migration Playbook
Migrating away from AWS S3 after years of use is one of the more technically demanding operations in WordPress infrastructure management. It is not like changing hosting providers, where you move files and update DNS. With S3, the complication is that image URLs are embedded throughout your content. Every post that contains an image, every page with a featured image, every WooCommerce product with gallery photos contains direct S3 bucket URLs or CloudFront distribution URLs referencing your specific bucket.
A site with three years of content and 1,000 products might have 50,000 or more individual image URLs stored in its database, embedded in post content via Gutenberg block JSON, referenced in page builder data stored in postmeta, and included in sitemap XML files that have been indexed by search engines. Moving the files to FTP is straightforward. Making all those URLs point to the new CDN domain without a single broken image during or after the migration is where the real complexity lies.
This guide is the definitive migration playbook for this specific scenario. It covers every location where S3 URLs are stored, the order in which to address them, the tools and commands for each step, and the verification process that confirms zero broken images before you shut down S3. It is the guide that should have existed when you set up S3, explaining how you would leave if you ever needed to.
A complete inventory of where S3 URLs live in WordPress
Before beginning any migration, you need to understand every location in your WordPress database where S3 URLs are stored. Missing even one location results in broken images after the migration. This inventory is the foundation of a complete migration.
Every image inserted into post or page content contains its full URL in the post_content column. In classic editor posts, these appear as standard img src attributes. In Gutenberg posts, they appear inside block JSON within the post_content as both “url” values and as part of the HTML embedded in the block markup. This is the largest concentration of S3 URLs.
SELECT COUNT(*) FROM wp_posts
WHERE post_content LIKE ‘%s3.amazonaws.com%’
OR post_content LIKE ‘%your-bucket-name%’;
Featured images are stored as attachment IDs in _thumbnail_id, not as URLs — so these do not need URL replacement. However, _wp_attachment_metadata stores the file paths and S3 URLs for each attachment’s source file and thumbnails. WP Offload Media stores additional metadata including the S3 bucket and path here. This metadata drives WP FTP Media’s URL rewriting after migration.
SELECT COUNT(*) FROM wp_postmeta
WHERE meta_key = ‘_wp_attachment_metadata’
AND meta_value LIKE ‘%amazonaws%’;
The wp_options table stores theme customizer settings (header images, background images, logo URLs), widget content that may include images, WooCommerce settings that reference images, and various plugin settings. Many of these contain absolute URLs to S3-hosted images that were set years ago and forgotten.
WHERE option_value LIKE ‘%s3.amazonaws.com%’
OR option_value LIKE ‘%cloudfront.net%’;
Page builders store their layout and content data in wp_postmeta, often as serialized PHP arrays or JSON strings. These data structures contain image URLs embedded within nested data. Standard database search-and-replace tools handle this correctly if they understand serialized data structure — tools that do not understand serialization will corrupt the data.
WHERE meta_key LIKE ‘_elementor%’
AND meta_value LIKE ‘%amazonaws%’;
The guid column in wp_posts stores the permanent URL for each attachment. WP Offload Media typically sets the guid to the S3 URL. While WordPress does not use the guid for frontend display (it uses attachment metadata and URL rewriting instead), some plugins and caching systems reference the guid. Updating the guid to the new CDN URL during migration ensures consistency.
S3 or CloudFront URLs may be present in XML sitemaps that have been indexed by search engines, in external sites that have linked directly to your images, in email newsletters that were sent containing S3 image links, and in CDN caches that will eventually expire but show old URLs until they do. These external references cannot be changed from within WordPress — they require either permanent S3 redirects or acceptance that old external links will eventually break as S3 is shut down.
The three migration strategies: choosing the right approach
Three approaches are available for migrating from S3 to FTP. They differ in how they handle the URL transition and what they require from the database.
Point your CDN to the FTP server. Create a custom subdomain for image delivery (e.g., cdn.yoursite.com). Configure WP FTP Media to use this custom CDN domain. Perform a database search-and-replace from the old S3/CloudFront URL to the new CDN domain. Because you own cdn.yoursite.com, you can later change what it points to (different CDN, different storage) without another database replacement.
Zero broken images if: The custom CDN domain is configured and serving images from FTP before the database replacement is run.
Configure the S3 bucket to redirect all requests to the new CDN URL. All existing S3 URLs continue to work because they redirect 301 to the corresponding CDN URL. No database changes are needed. WP FTP Media handles new uploads going forward. Old content keeps serving correctly via redirect. The S3 bucket must remain active for as long as the redirects need to function.
Limitation: S3 costs continue as long as redirects are needed. Not suitable for complete S3 shutdown.
WP FTP Media rewrites all image URLs at render time. Configure it with the old S3 domain as the “from” domain and the new CDN domain as the “to” domain. Every page render automatically outputs CDN URLs regardless of what is stored in the database. The S3 URLs remain in the database but are never exposed to browsers. This is the fastest strategy but requires that WP FTP Media is always active for the rewriting to function.
Risk: If WP FTP Media is ever deactivated, all images break immediately. Database cleanup recommended as a follow-up step.
The step-by-step migration sequence
The following sequence uses Strategy A (custom CDN domain) which is recommended for most sites conducting a complete S3 exit. Each step must be completed in order.
This is non-negotiable. Export the full database to a SQL file, store it offsite, and test the restore on a staging environment before proceeding. The database search-and-replace in Step 6 is irreversible on the live database without this backup.
Create the Hetzner Storage Box or equivalent FTP account. Set up a BunnyCDN or Cloudflare pull zone. Configure a custom CNAME record: cdn.yoursite.com pointing to the CDN zone’s hostname. Verify the CDN URL resolves correctly by uploading a test image to FTP and confirming it loads from cdn.yoursite.com/test-image.jpg before proceeding.
Use the AWS CLI to sync the S3 bucket to a local directory, then upload from local to FTP via rsync or FileZilla. Preserve the exact directory structure — the paths must be identical on FTP to what they were on S3 for the URL rewriting to work correctly. For a large library, this step may run overnight.
rsync -avz ./local-backup/ [email protected]:/uploads/
Install WP FTP Media. Configure the FTP connection pointing to your new FTP server. Set the CDN base URL to cdn.yoursite.com. At this point, enable WP FTP Media’s URL rewriting to replace the old S3/CloudFront domain with cdn.yoursite.com in all rendered output. Test several posts and product pages to verify images now load from cdn.yoursite.com using files served from the FTP server.
Before running on production, clone the production database to staging and run the full search-and-replace on staging. Verify staging renders all images correctly. This confirms the replacement logic is correct and handles serialized data in page builder postmeta without corruption.
wp search-replace ‘https://your-bucket.s3.amazonaws.com’
‘https://cdn.yoursite.com’ –all-tables –report
With the staging verification complete, run the same WP-CLI command on production. For a site with 50,000 image references across 1,000 posts, this command typically completes in 30 to 90 seconds. WP-CLI’s search-replace handles serialized data, JSON, and standard text across all tables. Replace the old S3 URL, old CloudFront URL (if used), and any http variants of both.
After the database replacement, the database contains CDN URLs directly. Deactivate WP Offload Media. Images should still load because they are now pointing to cdn.yoursite.com in the database and WP FTP Media handles new uploads going forward. If any images break after deactivating WP Offload Media, there are URL patterns that were not caught by the search-and-replace — investigate those URLs and run targeted replacements.

Setting up S3 redirects for external links
Even after a perfect internal migration, external references to your S3 images persist. Blog posts on other sites that have embedded your images. Social media posts that contain direct S3 image links. Email newsletters sent over the years. These cannot be updated. The only option is to configure S3 to redirect these requests to the new CDN URL before shutting down the bucket.
{
“Condition”: {},
“Redirect”: {
“Protocol”: “https”,
“HostName”: “cdn.yoursite.com”,
“HttpRedirectCode”: “301”
}
}
]
With this redirect rule configured, any request to your S3 bucket (whether through the S3 URL directly or through CloudFront if it is still pointing to the bucket) will 301 redirect to the corresponding path on cdn.yoursite.com. Because the redirect preserves the path, an old S3 URL for /wp-content/uploads/2023/product.jpg redirects to cdn.yoursite.com/wp-content/uploads/2023/product.jpg — which is exactly where the file now lives on the FTP server. Leave these redirects in place for 12 to 18 months to capture the long tail of external references before shutting down the bucket entirely.
The verification checklist: confirming zero broken images
— Target: 0
Open 10 different post types (post, page, product, category, home page) in Chrome DevTools. Filter the Network tab by “Img”. Verify all image requests go to cdn.yoursite.com. No requests should go to s3.amazonaws.com or your CloudFront distribution domain.
Run Screaming Frog or a similar crawler across the entire site specifically checking image URLs. Any 404 responses from cdn.yoursite.com indicate files that exist in the database but were not transferred to FTP during Step 3. Download missing files from S3 (which still has the originals) and upload them to FTP.
Place a test order and check the order confirmation email. Product images in WooCommerce emails are often rendered server-side from the postmeta data at send time. Verify that product thumbnails in the order confirmation email show correctly from the CDN domain. WooCommerce order emails are a commonly missed location for broken images post-migration.
After migration, monitor the Google Search Console Enhancement report and the Core Web Vitals report for 4 to 6 weeks. Image indexing should transition from the S3 domain to the CDN domain over this period as Google recrawls pages. A spike in crawl errors in the S3 redirect period confirms that Google is finding and following the 301 redirects correctly.
According to the official WP-CLI documentation for the search-replace command, the –all-tables flag and correct handling of serialized data are critical for WordPress migrations involving URL replacement. The documentation explicitly warns against using simple SQL UPDATE statements for URL replacement in WordPress because they do not handle PHP serialized arrays correctly — the same PHP-serialized data that page builders and WooCommerce use to store their content.
A complete S3 exit is a significant infrastructure operation but a fully manageable one when approached with the right sequence and verification steps. WP FTP Media’s comprehensive WordPress S3 exit and FTP migration plugin is the destination infrastructure that makes leaving S3 worthwhile: the same CDN-delivered, flat-rate-priced, inode-unconstrained media architecture that this entire guide series has been building toward — now with a clear, verified, zero-broken-image migration path to reach it.

50,000 image links. One migration. Zero broken images. Your S3 days are done.
WP FTP Media is the destination for your S3 migration: flat-rate FTP storage, CDN delivery, no egress fees, and the URL rewriting infrastructure that makes a complete database transition from S3 domain to your own CDN subdomain clean, verified, and permanent.
This saved my site's pics totally worth it!
This guide saved me weeks of headaches when moving my business site off S3. the step by step on handling Gutenberg block JSON and serialized data? Absolute lifesaver I had no idea how buried those old URLs were in my posts. worth every penny just for the stress it saved me.
I bought this guide hoping it would address the nightmare of Gutenberg block JSON and page builder serialized data during URL replacement, but it barely scratches the surface. the section on handling embedded URLs in post content is so vague it might as well not exist
Hey everyone! just finished migrating my WordPress site away from S3 using this guide, and wow I had no idea how many hidden image URLs were lurking in my database. Like, tens of thousands embedded in old posts, cached in CDN, even referenced in sitemaps