Support » Networking WordPress » htaccess causing 404 in ONE directory (WP Multisite)

  • Hi,

    We just migrated our site (www.iurisonline.com) to WP. We need a multisite configuration, and followed instructions to do so.

    We created an .htaccess (see code below) which causes 404 in the following directory http://www.iurisonline.com/files/ Which happens to be essential for us.

    The rest of the two sites are working fine. Our host provider (iPage) says it’s caused by the .htaccess file in root. But they wont debug our code.

    Any ideas?

    Thanks in advance,
    Alejandro

    Here is the code:

    DirectoryIndex home.html index.html index.php
    
    ErrorDocument 403 /404.php
    ErrorDocument 404 /404.php
    
    Options +FollowSymlinks
    
    #Weebly Additions Start
    #Weebly Additions End
    RewriteCond %{SERVER_PORT} !^443$
    rewriterule ^(.*)$ https://www.iurisonline.com/$1 [r=301,nc]
    
    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # uploaded files
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
    
    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
    RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]
    # END WordPress
Viewing 15 replies - 1 through 15 (of 56 total)
  • Hi

    WordPress Multisite uses the path /files/ on each site as an alias to the actual folder in which that site’s image and other files are placed. It is the Multisite equivalent of the location /wp-content/uploads/ which is used for that purpose on all single install WP sites, and on the root site of most MultiSite installs.

    Each site on a Multisite install has a unique blog ID. The default location of their upload files is
    /wp-content/blogs.dir/3/files/ where 3 is the blog id. Thus 3 would be 11 on the site with the blog ID 11.

    WordPress uses a convention of /wp-content/files/ as a shortened URL so the same URL can be used on every site for the uploads location even though the physical disk folder is different on each site. I don’t know offhand if the translation is done in the rewrite code that Multisite puts in the .htaccess file, or in WordPress’ internal rewrite code, but the end result is the same, /wp-content/files/ is rewritten as /wp-content/blogs.dir/3/files/ on site 3

    This is why you are having a problem with files in a folder named /files/

    Now, I just checked and found there is a setting in each site’s Edit Settings screen for File Upload URL, which defaults to (on a subdomain installation) http://subdomain.example.com/files
    This means that entry can be changed. I have never done this and I don’t know if it will work consistently. If it works it would have to be changed on every site as new sites are set up, unless there is a way to hook the base code and permanently change the default in a plugin. It may also be that WordPress expects to have /files/ as this base URL and you just can’t change it.
    I’m not familiar enough with those aspects of Multisite’s code to be able to answer that. You may want to repost your question in the MultiSite forum worded as “Can the default uploads location of /file/ be changed?”
    I thought I would answer with as much as I knew hoping it points you towards a more complete response.

    Thanks a lot.

    I’ll ask in MultiSite forum.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    πŸ³οΈβ€πŸŒˆ Halfelf Rogue & Plugin Review Team Rep

    WordPress uses a convention of /wp-content/files/

    Actually it’s just /files/ but that’s okay.

    Now, as you’re IN the multisite section, the answers are as follows:

    1) Yes you can change /files/ but you shouldn’t (you have to manually edit every site after it’s generated).

    2) Can you just move the OTHER /files/ folder?

    Thanks for the comment.

    Moving the OTHER folder doesn’t seem to be that easy. A lot of code in our site refers to that folder. Changing the folder results in multiple errors.

    So before hiring someone to check all the code, we were wondering if there is an easier way to do it.

    What does “manually edit every site after it’s generated” mean? We will only have 2 sites (Site in English / site in Spanish) maybe a 3rd one in French in the future. So if we can fix it by editing a few lines for each site, that will be better than debugging the entire code.

    Regards,

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    πŸ³οΈβ€πŸŒˆ Halfelf Rogue & Plugin Review Team Rep

    You’d have to go into wp-admin -> Network -> Sites and EDIT each site. Then go to the settings tab and look for /files/ where it’s NOT /blogs.dir/#/files/ and change that to whatever you want.

    Then you change the .htaccess:

    RewriteRule ^([_0-9a-zA-Z-]+/)?NEWLOCATION/(.+) wp-includes/ms-files.php?file=$2 [L]

    But I’ve never tested that and I can’t swear it’d work.

    Hi,

    Thanks again.

    I must be doing something wrong.

    When editing sites, I only find /files in the uploading path of one of the sites: wp-content/blogs.dir/4/files.

    :-/

    Do we solve the problem by creating a network without subfolders, like english.iurisonline.com/ instead of iurisonline.com/en/?

    How can this be done?

    Regards,

    The /files/ subfolder in blogs.dir is created the first time you upload something using the media library on a site. Most likely you’ve not yet uploaded any images on the sites that don’t have that folder. Is that correct?

    That has nothing to do with whether you use folders or subdomains to designate the different sites. That is a decision “subdomain or folder” that was made on the initial Multisite install. If you didn’t decide then you accepted the default. It used to be you could not change to the other approach once the installation was in place. I think that may have changed in recent versions, to where you can switch. However switching does not resolve your core issue, which is your need to have /files/ available for non-WordPress purposes on each site.

    Ipstenu’s last statement “But I’ve never tested that and I can’t swear it’d work.” is basically what I said in my original email. Multisite is designed to have /files/ as the upload folder location on each site. Although it allows you to change that, the results of doing that are unknown – whether it will have unforeseen side effects in obscure parts of the Multisite code.

    Also, the original site, the root site, by default does not use blogs.dir/1/files, nor does it use /files/ – its images are located in /wp-content/uploads/

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    πŸ³οΈβ€πŸŒˆ Halfelf Rogue & Plugin Review Team Rep

    stvwlf, you’re somewhat incorrect. The /files/ folder is virtual.

    It does not get created. Ever πŸ™‚

    The setting option you’re looking for is “Fileupload Url”

    Ipstenu

    You somewhat misread the poster’s email and my response. He was referring to the /files folder that is created in /blogs.dir/4/ when he said that “the /files/ folder in those sites did not exist within the blogs.dir folder.” If you reread my answer you will see that is what I was referring to.

    As you know, the /files/ folders within blogs.dir is never virtual and is always physical.

    I am quite aware that /files/ is virtual and is never created as a physical folder. My answers above have referred to it being a placeholder or shortcut to the full path to blogs.dir/3/files several times.

    My concern here is in confusing the poster when you are posting that what I said is not completely correct, when it is. I understand you did not see the full context of what I was saying when you replied.

    thank you

    Thanks very much,

    I changed the Fileupload url to something different (http:www.iurisonline.com/en/archivos) instead of “en/files”, quite unsuccessfully, I might say.

    Both sites work with the same /files folder for non WP purposes.

    The reason we need two sites is to have two languages working, with two menus, etc…

    When we eliminate the .htaccess file the entire root site works fine. But the “/en” site doesn’t work.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    πŸ³οΈβ€πŸŒˆ Halfelf Rogue & Plugin Review Team Rep

    Ah. I did missread (though note the /4/ wouldn’t exist either, stvwlf. They’re all created on first upload πŸ˜‰ If you have /blogs.dir/4, then you should have /blogs.dir/4/files, or your PHP permissions are wonky. Which is totally possible. Happens a lot. But that’s why I try to use the FULL path for these things, since /files/ is gonna get confusing real fast. Also please use blockquotes, it helps formatting.)

    And NONE of that is the point for poor acollantes (unless, like me, he likes getting more info)!!

    I changed the Fileupload url to something different (http:www.iurisonline.com/en/archivos) instead of “en/files”, quite unsuccessfully, I might say.

    What didn’t work? You changed it to archivos and did you ALSO change the .htaccess?

    The main site doesn’t use files, as stvwlf mentioned. You only need to edit the children.

    Yes. I did both, and used the line you proposed for .htaccess It remains as follows:

    DirectoryIndex home.html index.html index.php

    ErrorDocument 403 /404.php
    ErrorDocument 404 /404.php

    Options +FollowSymlinks

    #Weebly Additions Start
    #Weebly Additions End
    RewriteCond %{SERVER_PORT} !^443$
    rewriterule ^(.*)$ https://www.iurisonline.com/$1 [r=301,nc]

    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]

    # uploaded files
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ – [L]
    RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
    RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?NEWLOCATION/(.+) wp-includes/ms-files.php?file=$2 [L]
    # END WordPress

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    πŸ³οΈβ€πŸŒˆ Halfelf Rogue & Plugin Review Team Rep

    You have to REMOVE the other one πŸ˜‰ Do this:

    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # uploaded files
    # RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?NEWLOCATION/(.+) wp-includes/ms-files.php?file=$2 [L]
    
    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
    RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]
    # END WordPress

    Β‘Aleluya!

    Thanks for your patience Ipstenu and stvwlf.

    Please feel free to contact me if you ever need a lawyers network service in Spain.

    Or mention Alejandro Collantes if you ever use http://www.iurisonline.com

    Regards,
    Alejandro

    It is not OK yet πŸ™

    When trying to upload files to the child site, the administrator’s tool finds the pictures correctly, but fails to upload them properly.

Viewing 15 replies - 1 through 15 (of 56 total)
  • The topic ‘htaccess causing 404 in ONE directory (WP Multisite)’ is closed to new replies.