Changing upload folder to subdomain

So I would like to move my media library to a subdomain on my server. I was able to successfully create the subdomain, transfer all my old files and run a SQL script to change the URL in all my posts.

I am having an issue with uploading new images via the Media Library.

Whenever I try and do so, I see a broken link and even though the URL seems to be right, the image file never makes it to the subdomain folder. I can manually upload the file to that location via FTP and the image link in the Media Library starts to work again.

How can I prevent this and only upload new images via the Media Library to a folder within my subdomain?

Any help is appreciated.

Thanks,
Judah

  • Vinod Dalvi

    Hi Judah,

    I hope you are well today and thank you for your question.

    I can see all of your sites created using subdirectory so just want to confirm are you talking about subdomain or subdirectory or may be the site that you are talking about is not listed at our side?

    Uploading file in the media library should work without any issue if you have moved your site properly.

    Would you mind if I logged in to your site and did some troubleshooting? This might help get to the bottom of this faster. If this is ok, just grant me temporary admin access to your site by clicking "Grant Access" button in the WPMU DEV Dashboard Settings as described on the following page and reply on this thread after granting it?

    https://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    Kind Regards,
    Vinod Dalvi

  • Judah

    Hey @Vinod Dalvi,

    I can see all of your sites created using subdirectory so just want to confirm are you talking about subdomain or subdirectory or may be the site that you are talking about is not listed at our side?

    My current site is in a subdirectory on the root domain (the names are the same, but I placed it in a subdirectory for organizational purposes). I have 5 other sub-domains(one of them is called images.mysite.com or public_html/images).

    My current site is not a sub-domain, its a subdirectory in the root folder.

    My image location is a sub-domain called images.mysite.com

    I would like for all new uploads to my site, to be uploaded to the images.mysite.com/media folder

    I was able to link all the old items already but the new images are not making it to the new folder/sub-domain.

    I hope that clears it up a bit.

    I just extended access (I clicked it right before I saw you logged in 20 min ago) Sorry!

    Please let me know if you have any additional questions.

    The credentials I sent you in the past are still active and you should have access to ftp/cpanel/admin if necessary.

    Thanks,
    Judah

  • Judah

    Hey @Ashok,

    I am glad that you can recognize/identify the issue.

    I followed this blog post in order to make the original changes.

    Everything was working, until I tried uploading new images.

    I tried using a plugin called WP Original Media Path to change the values but it was not correcting the issue. In one of the support posts another person was having a similar issue and suggested this plugin. I could not get this plugin to work properly (it may have even broke my theme until I commented out the file changes in wp-config).

    I checked the perms on my folders and they are set to 755.

    I am confused because when I upload an image to the media library, it "uploads" it but the file never makes it to the location it specifies on the server.

    Any help is appreciated.

    Thanks,
    Judah

  • Ash

    Hello @Judah

    I hope you are well today.

    I have talked to a SLS developer @Hoang Ngo about this. He will be going to take a look.

    Would you please send me admin login details and FTP details?

    To send me details, please use our contact form: https://premium.wpmudev.org/contact/

    Select: I have a different question
    Subject: Attn-Ash (this ensures that it will be assigned to me)
    Details:
    1. Send all requested details
    2. Send a link of this thread so that I can track
    3. Send any other relevant link

    I will be happy to take a look :slight_smile:

    Cheers
    Ash

  • Hoang Ngo

    @Judah,

    Please add this code to your theme functions.php or use mu-plugins

    add_filter('upload_dir', 'update_attachment_url');
    function update_attachment_url($data)
    {
        $data['url'] = str_replace('http://main-domain/', 'http://sub-domain.com', $data['url']);
        $data['baseurl'] = str_replace('http://main-domain/', 'http://sub-domain.com', $data['baseurl']);
        return $data;
    }

    This will force the upload_dir url to subdomain, let's see if it can help :slight_smile:

    Best regards,
    Hoang

  • Judah

    Hey @Hoang Ngo,

    I tried your code and it did move the upload folder around but did not solve the issue.

    I changed all the code back to normal, changed all the URLs back to normal and took out your code and now everything is back to the basics.

    I will not be continuing with this as of today because I have other tasks that need to be completed with a semi-working media library.

    We were so close.. I will follow up here in the near future when I can try and figure this out.. I have a list of about 20+ solutions that may work but I want to test on a different domain as this one is live and testing this out on a local environment is something I am not sure how to do.

    If you have any additional ideas that could help that would be great.

    Thanks,
    Judah

  • Judah

    Hey @Hoang Ngo,

    I got everything to work properly except the new images.

    The new images never made it to the stated location on the subdomain.

    I got the below to work:
    1. All old posts changed the image links to new subdomain.
    2. All new media library images had correct upload link to the subdomain ** The link structure was working however the images never appeared on the server.

    I don't mind you testing. All of my current images are on the regular domain and subdomain. But I ask that you do change the settings back to the original way they were when you are done.

    Please let me know if/when you will be working on this as I know @Ashok is going to be accessing my website at some point soon and I am making a few changes (different location).

    Thanks,
    Judah

  • Hoang Ngo

    Hi @Judah,

    I hope you are well today and sorry for the long delay.

    Just for clarification, I have some questions.

    1. Does your subdomain is a sub-blog on your network, or it just a subdomain you created by cPanel?
    2. When new image uploaded, do you have any scripts to move that file to your specific location, or currently, we just let WordPress process that as usual?

    Please advise,
    Thanks!

    Best regards,
    Hoang

  • Patrick

    Hi there @Judah

    I hope you don't mind me jumping in here.

    Basically, you just need to define that location in your wp-config.php file. Fortunately, you're not the only one who wants to do things that way, and I found a nice little tutorial to get you going:
    http://www.webnots.com/change-default-media-upload-folder-wordpress/

    See this section (just before the comments at the bottom):
    Create a new folder on a subdomain outside your WordPress installation

    I hope this helps! And thanks for being a member :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.