Moving uploads directory above wordpress directory. UPLOADS location in parent directory

Now, do not ask me why, but the UPLOADS constant the upload_path option seem to work different.

While declaring define( 'UPLOADS', '../uploads' ); generates this:

https://staging.mywebsite.com/core/../uploads/2024/02/image.png

Removing that declaration and filling the upload_path option instead with the same value ../uploads gives a different result:

https://staging.mywebsite.com/uploads/2024/02/image.png

with the images being uploaded in the path I wanted and the media URLs well formatted.

This is the working setup and I hope the behaviour never randomly changes:

Structure

Requires setting up a copy in the main directory of the index.php found in the WordPress directory.

public_html/
-> content/
|--> plugins/
|--> themes/
-> core/
|--> wp-includes/
|--> wp-admin/
|--> etc
-> uploads/
-> wp-config.php 
-> index.php

Main index.php

<?php
define( 'WP_USE_THEMES', true );
require( './core/wp-blog-header.php' );

wp-config.php

Only the important part, of course you need the rest of your file with your database settings and everything. Do NOT declare the UPLOADS constant or it will mess everything up.


/* Add any custom values between this line and the "stop editing" line. */

define( 'WP_SITEURL', 'https://staging.mywebsite.com/core' );
define( 'WP_HOME', 'https://staging.mywebsite.com' );

define( 'WP_CONTENT_DIR', dirname( __FILE__ ) . '/content' );
define( 'WP_CONTENT_URL', 'https://' . $_SERVER['HTTP_HOST'] . '/content' );

// NO. DON'T. DO NOT EVER DECLARE IT. 
//define( 'UPLOADS', '../uploads' );

/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
    define( 'ABSPATH', __DIR__ . "https://wordpress.stackexchange.com/" );
}
/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

Database options

Most important part. And risky, as they may not always exist in the wp_options table, as well as they may be overwritten by the wrong value when migrating websites or restoring DB backups.

Remember to pay attention to them. If the value of any of them is different than an empty string, you will be able to edit them from Settings -> Media -> Uploading Files. If you are having trouble again with the uploads directory or URLs and they have disappeared from that settings section, is because their values have changed back to empty string or they have been deleted. You will need to use phpMyAdmin or any other tool to add/edit them again.

The right values:

upload_url_path = https://staging.mywebsite.com/uploads
upload_path = ../uploads

I hope this can help other people to not go insane trying to figure out why it isn’t working, and I will surely be coming back to this as well.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)