Unable to change media library file path


(Thesesameshop) #1

Hi, I migrated my website from a traditional shared hosting where my images are served from a subdomain. All the media library file path are coded to this extremely long path "http://woocommerce-123456-123456.cloudwaysapps.com//home/123456.cloudwaysapps.com/xxxxxx/public_html/sub.domain.com/xxxxxx.png"
I’ve changed the “upload file path” and “upload file url” in the “wp_options” table in the database, but all new uploads continue to go to that long path above.
I’ve got a separate application setup for the images domain, I’ve tested the links are working.
How do I point the media library file url to my images application?
Thanks.


(Mustaasam Saleem) #2

Hi @thesesameshop

You need to do the following:

  1. Visit here:
    http://yoursite.com/wp-admin/options.php
  2. Search for upload_url_path
  3. Enter the subdomain URL without the trailing slash and click on save at the bottom of the page
    http://sub.yoursite.com
    By changing this, all images uploaded via Add Media from the primary domain will be uploaded to the subdomain.
  4. Copy all images from primary site to the subdomain.
  5. Replace existing image URLs in the database.
    UPDATE wp_posts SET post_content = REPLACE (post_content,'http://yoursite.com/wp-content/uploads/','http://img.yoursite.com/');

I would suggest to give it a read thoroughly.
https://scottdeluzio.com/serve-images-from-sub-domain-in-wordpress/


(Thesesameshop) #3

Hi Mustaasam,

As I mentioned in my post, I’ve done all these already. My images were successfully serving from the subdomain with my previous shared host. When I migrated to Cloudways, all the urls have changed and changing upload_url_path or the upload_path doesn’t change the url. Database search doesn’t find anything in wp_posts. Are you able to get in my site and have a look?


(Thesesameshop) #4

I found the issue. The uploads path has been hard coded into the wp_configs.php.
However, I also found that it is not possible to serve images from a subdomain with the “applications” arrangement in Cloudways. It wouldn’t upload to root folder of another “application”, which is your subdomain.


(Mustaasam Saleem) #5

Hi @thesesameshop

Thanks for the update. How about creating a folder something like "Images’, so that the URL looks like:
http://sub.site.com/Images

Try it out, it should work fine. :slight_smile:

P.S: I didn’t test it. If that doesn’t work, let me know.