WordPress.org

Ready to get started?Download WordPress

Forums

htaccess causing 404 in ONE directory (WP Multisite) (57 posts)

  1. acollantes
    Member
    Posted 2 years ago #

    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
  2. stvwlf
    Member
    Posted 2 years ago #

    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.

  3. acollantes
    Member
    Posted 2 years ago #

    Thanks a lot.

    I'll ask in MultiSite forum.

  4. 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?

  5. acollantes
    Member
    Posted 2 years ago #

    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,

  6. 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.

  7. acollantes
    Member
    Posted 2 years ago #

    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,

  8. stvwlf
    Member
    Posted 2 years ago #

    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/

  9. 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"

  10. stvwlf
    Member
    Posted 2 years ago #

    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

  11. acollantes
    Member
    Posted 2 years ago #

    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.

  12. 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.

  13. acollantes
    Member
    Posted 2 years ago #

    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

  14. 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
  15. acollantes
    Member
    Posted 2 years ago #

    ¬°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

  16. acollantes
    Member
    Posted 2 years ago #

    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.

  17. acollantes
    Member
    Posted 2 years ago #

    Upload path is wp-content/blogs.dir/4/archivos

    Content is there, as I can see it through FTP tool. But WP doesn't take it to the post.

    Thanks for everything,
    Alejandro

  18. stvwlf
    Member
    Posted 2 years ago #

    Ipstenu will need to help you with this as its most likely the htaccess rewrite code. It might be useful to post the current content of your htacess file again.

  19. acollantes
    Member
    Posted 2 years ago #

    I see now that this is what stvwlf was referring to when he said:

    Most likely you've not yet uploaded any images on the sites that don't have that folder. Is that correct?

    Yes. It was correct. Now trying to put some content to child site I see the problem.

  20. stvwlf
    Member
    Posted 2 years ago #

    Actually I looked further into what you quoted from me after something Ipstenu said, and she was correct and what I said was incorrect.

    When the /blogs.dir/4/ folder is created, the /blogs.dir/4/files/ folder is also created at the same time. If you see /blogs.dir/4/ and do not see /blogs.dir/4/files/ this is a server misconfiguration issue as they are both created at the same time. Since you only have 4 sites, at this point you can manually create the /files/ subfolders of /blogs.dir/4/files/ and the other sites since its a one time task.

    Another thing, check the folder permissions on all of these folders. On most server configurations they should all be 755. Overly restrictive permissions can prevent WordPress from having write access to the folder, which might be why you can't upload.

    (You don't want 777 permissions as this lets anyone write and delete and change files in those folders.)

    If you don't know about permissions these can be set either in an FTP program (usually by right clicking on the folder name) or in the web hosting control panel's file manager.

  21. Upload path is wp-content/blogs.dir/4/archivos

    No no no.

    Upload path is wp-content/blogs.dir/4/FILES

    The ONLY URL you change is "Fileupload Url" (i.e. domain.com/files/ to domain.com/archivos )

  22. acollantes
    Member
    Posted 2 years ago #

    OK. Fileupload URL is now http://www.iurisonline.com/en/archivos/ and Upload path is wp-content/blogs.dir/4/files

    Sorry. Ignorance is vast and has no limits :-/

    Funny thing is that there are no 4 sites. Just root and /en/

    wp-content/blogs.dir/4/files/ is there, and it has 755 permission. It has even created a /wp-content/blogs.dir/4/files/2012/05 folder, but it is empty.

  23. acollantes
    Member
    Posted 2 years ago #

    Thanks guys. You are being very patient.

  24. It has even created a /wp-content/blogs.dir/4/files/2012/05 folder, but it is empty.

    Have you uploaded anything this month? ;) (When you make a post in May it makes the folder in antici.... pation.)

    The number 4 references the site ID. Site #1 is your main site. I'll bet you made two subsites (2 and 3) and deleted them.

  25. acollantes
    Member
    Posted 2 years ago #

    I've tried to upload content to the /en/ site. But I can't get it done: I chose a file from my computer, it seems to be uploaded, since I see the picture gallery in the administrator's desktop (or whatever it's properly called), but it fails to insert the pictures in the post.

    Thans again,

  26. stvwlf
    Member
    Posted 2 years ago #

    When you say "it fails to insert the pictures in the post." that could mean two things. Do you mean no code is inserted into the post in the editor, or the picture does not appear on the website when you look at the post on the front end of the site?

    In the editor, open that post and switch to the HTML tab. Look for the HTML code for the image you inserted - see if it is there. It is possible it is inserting a source URL for the image that is not letting the browser find the image when it displays that post on the front end.

    In other words, what is the URL of the image's source that WordPress is inserting into the post? If there is still an htaccess redirection issue the browser may not find the image at that URL.

  27. None of your CSS is showing up on http://www.iurisonline.com/en/

    Did that work BEFORE we started messing with this?

    Does your .htaccess look like 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-]+/)?archivos/(.+) 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
  28. acollantes
    Member
    Posted 2 years ago #

    First:

    Url of a particular pic is:
    <img class="alignleft size-full wp-image-11" title="Ask a lawyer" src="http://www.iurisonline.com/en/files/2012/05/consulte3.jpg" alt="Ask a lawyer" width="674" height="437" />

    I realise now that thumbnail is not shown when I access the gallery.

    Second, there was an error in my .htaccess as this line

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

    It was still NEWLOCATION

    I changed it now for:
    RewriteRule ^([_0-9a-zA-Z-]+/)?archivos/(.+) wp-includes/ms-files.php?file=$2 [L]

    Please think that I copy/paste the code you send, since it is almos Greek to me :-(

    CSS seems to be working now

  29. stvwlf
    Member
    Posted 2 years ago #

    My two cents to add is:

    http://www.iurisonline.com/en/files/2012/05/consulte3.jpg is the URL where WordPress is instructing the browser to request the image file. When I paste that URL in my browser address bar I get a 404 "not found" error. Most likely that is due to /files/ part of that URL not being redirected correctly due to the ongoing htaccess issues. That is the issue Ipstenu is working with you to correct.

  30. acollantes
    Member
    Posted 2 years ago #

    For some reason http://www.iurisonline.com/ is not working in Safari. But it does work in Firefox or Chrome :-$

    It also works in Safari with https://www.iurisonline.com/

    In case it has anything to do with all this

Topic Closed

This topic has been closed to new replies.

About this Topic