WordPress.org

Forums

[resolved] Looking for file URL rewriting best practices (trying to emulate pre-3.5 style) (7 posts)

  1. maiki
    Member
    Posted 1 year ago #

    I've been running a multisite instance since before 3.5, so the new uploads and URL structure caught me by surprise when I set up a new network.

    I've been poking around for a few hours, and all the docs and posts talking about moving directories around and whatnot. I am interested in creating custom file URLs, either network-wide or per-site, in the style of pre-3.5 instances.

    An example:

    example.com/wp-content/uploads/sites/6/abc.png => example.com/files/abc.png

    Are there acceptable or popular ways to do this that I am not aware of? Your advice is appreciated. ^_^

  2. Ryan Kanner
    Member
    Posted 1 year ago #

    You can change the upload path on a site by site basis in the network admin. Go to your site list in the network and hit the "edit" button for that site. Now hit the "settings" tab at the top and there is a field labeled "Upload Path". You can specify a custom path here, or leave it blank to use the default path.

  3. Ryan Kanner
    Member
    Posted 1 year ago #

    You can also change the default path in your config file:

    define( 'UPLOADS', 'wp-content/'.'newfolder' );

    This will make the default path domain.com/wp-content/newfolder

  4. maiki
    Member
    Posted 1 year ago #

    Thanks for the reply. That isn't what I am looking for. I don't want to change the upload path. I want to rewrite the path in the URL.

    Using the method you posted, which is documented in the codex, changes the directory in the filesystem where the file is uploaded and saved. If I upload to a site that has the ID 6, and change the upload path to "files", I get a file saved in a files directory in my WordPress root. Also, it still appends /sites/6 to the URL.

    So, uploading abc.jpg is served at example.com/files/sites/6/abc.jpg.

    What I want is for the URL to be example.com/files/abc.jpg, regardless of where the file lives in the filesystem (the default is fine with me). This is how the files are served from my current sites on a pre-3.5 instance, and I like it. However, it makes use of ms-files.php and .htaccess rewrite rules. I am looking for a similar set of rules, for either network-wide rewriting, or for individual sites.

    Does that make more sense?

  5. WordPress USED to do that out of the box, you're right. It stopped because doing that was putting undue load on servers and causing conflicts with plugins. In general, it's not a great idea.

    In your database, go into wp_sitemeta

    Look for ms_files_rewriting - I THINK if you set that to true, it'll force WP to use the old ms-files stuff.

  6. maiki
    Member
    Posted 1 year ago #

    Thanks for replying.

    I am not inclined to use ms-files.php, I was just wondering if there was a way to emulate it otherwise. I like having short file URLs.

    I am guessing there isn't any other method folks are using, so I will drop my query.

  7. ms-files is the only way to pull it off, sadly.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags