WordPress.org

Ready to get started?Download WordPress

Forums

Error image path (20 posts)

  1. sarett
    Member
    Posted 2 years ago #

    Hi,
    I have searched the forum to find an answer but could not find one so I am posting a new thread.
    I'm running WordPress 3.3.1 in a Multisite. When I add media from one of the sites, the file gets uploaded and thumbnails are created in the proper directory (blogs.dir/2/files/2012/05/image.jpg) but when looking at the media record the thumbnails are blank and the Filename URL is incorrect.

    Details:
    When I create a post and insert an image the image come inserted following this path:
    http://www.site.com/blogs/wp-content/blogs.dir/2/files/2012/05/image.jpg where the absolute path pointing to visualize the image correctly.

    The problem is that the path entered in the post is as follows:
    http://www.site.com/blogs/bob/files/2012/05/image.jpg il which gives me a 404 - File not found, pointing directly at this location, I can't display the image in post.

    I have verified that the "Fileupload Url" (in Network Admin>Site>Edit>Settings) is as follows http://www.site.com/blogs/bob/files

    I think the problem probably lies in the following .htaccess:

    RewriteEngine On
    RewriteBase /blogs/
    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]

    Any help would be appreciated. I'm very frustated about this problem. Help me!

    Thanks in advance.

    Sara

  2. sarett
    Member
    Posted 2 years ago #

    UPDATE!

    I made some more investigations and i tried calling directly the ms-files.php from browser (like: http://www.site.com/blogs/wp-includes/ms-files.php) to see if it was accessible (i did already put file permissions to 755).

    I also modified it to echo informations to the page as follows:

    $file = rtrim( BLOGUPLOADDIR, '/' ) . '/' . str_replace( '..', '', $_GET[ 'file' ] );
    echo($wpdb->blogid);
    echo('</br>');
    echo(BLOGUPLOADDIR);
    echo('</br>');
    echo($_GET[ 'file' ]);
    echo('</br>');
    echo($file);
    echo('</br>');
    if ( !is_file( $file ) ) {
    	status_header( 404 );
    	die( '404 — File not found. xxx' );
    }

    and it echoes me the following informations:

    1
    /var/www/vhosts/site.com/httpdocs/blogs/wp-content/blogs.dir/1/files/

    /var/www/vhosts/site.com/httpdocs/blogs/wp-content/blogs.dir/1/files/
    404 — File not found. xxx

    so i understand the following:
    1) the blog #id used to compose the image path is 1, while my image resides in the blog id #2.
    2) i don't know if it's because i'm calling ms-files.php directly and thus completely outside blog context (from where i suppose it may get the right blog #id)
    3) but i can also see it is somewhat working, so at this point i think my htaccess doesn't have problems and ms-files.php neither.

    So why do i continue getting 404 errors on uploaded images when reading secondary blogs?

  3. sarett
    Member
    Posted 2 years ago #

    UPDATE #2:
    again, for testing purposes, i changed the file ms-default-constants.php hardcoding the id #2 in the following line:

    if ( 'wp-content/blogs.dir' == UPLOADBLOGSDIR )
    			//define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/{$wpdb->blogid}/files/" );
    			define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/2/files/" );

    and i opened my blog #2. Now the problem changed: the 404s were solved, but i got all the images not to be downloaded with firefox console giving me the following error:

    Image corrupt or truncated

    I then went via ftp to the uploading directory and downloaded some of the images, finding that they were completely ok. So i made a search and found out this ticket: http://core.trac.wordpress.org/ticket/14730

    I applied the following patch to ms-files.php:

    // If we made it this far, just serve the file
    ob_clean();
    flush();
    readfile( $file );
    flush();

    and now images are showing! But remember, i still have the blog id hardcoded to 2 in ms-default-constants.php

    If i change it back to normal {$wpdb->blogid} the 404s are back.
    :(

    please help me i don't know what more to do!!!!

  4. http://www.site.com/blogs/bob/files/2012/05/image.jpg is the correct URL. Promise. Don't mess with that.

    See this line?

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

    That tells /blogs/bob/files/2012/05/image.jpg that it's really /blogs/wp-includes/ms-files.php?file=/2012/05/image.jpg which is really http://www.site.com/blogs/wp-content/blogs.dir/2/files/2012/05/image.jpg

    So why isn't it working? 90% of the time it's because AllowOverride isn't set to ALL in your httpd.conf.

  5. wikkew
    Member
    Posted 2 years ago #

    Ipstenu. How do I set AllowOverride t ALL ? where do I find the httpd.conf?

    Do you think that it will fix the problem? (got the same as OP)

  6. sarett
    Member
    Posted 2 years ago #

    http://www.site.com/blogs/bob/files/2012/05/image.jpg is the correct URL. Promise. Don't mess with that.

    Hi Ipstenu, thanks for gettin back to me.
    I assure you i won't absolutely mess with paths.

    I have contacted my web host to verify the AllowOverride option, but i don't think it is related, because the .htaccess in root folder of the site works without any issue (i think i should specify i have a wordpress installation under a joomla site, so the root directory is the joomla one, and its htaccess file contains the proper rules to make it work, and it DOES work).

    I made sure to check all the things you mentioned in every thread i read on this forum before posting, and the only thing i'd like to know is if the problem emerged on my update #2 could have some explanation or not.

    I only had to change manually the ID of the blog to get the right image url (not messing with paths like you said above i swear!!!), so i think the rewrite is working: it is the part where wp gets the right blog id that fails!!!

  7. I have contacted my web host to verify the AllowOverride option, but i don't think it is related, because the .htaccess in root folder of the site works without any issue

    You'd think, but no. Specifically, your .htaccess is not being read completely. Otherwise it would be showing your image. Trust me :) Check that first before you start messing with the rest. And I refuse to look at core edits because that way lies madness. Never edit core.

    Your server's not passing images through wp-includes/ms-files.php correctly.

    This is usually the case of httpd.conf not having AllowOverride to All. The other main reasons are you have PHP in safe_mode, or SuHosin PHP.

    wikkew - Ask your webhost.

  8. sarett
    Member
    Posted 2 years ago #

    Webhost confirmed me my AllowOverride is set to All.

    I also passed him my .htaccess for checking if there were some wrong directives and he told me it works 100%.

    safe_mode is OFF and SuHosin is not installed...

  9. I may have missed it, but can you provide a link to an image that's not working correctly?

  10. sarett
    Member
    Posted 2 years ago #

    Hi Jan, thanks for your interest.
    I'm sorry but the site owner doesn't want me to publish links in public forums.

    In the meanwhile I checked something more.

    Since the site is pretty complicated and full of things and modules, i had made a staging site where i configured everything, and then i copied everything (filesystem, db, settings, etc.) into the production site.

    In the staging one, upload of pics and relative showing by posts or by direct link works; in the production one nope (with the problems i described above).

    So i made a diff over files and they are equal in both sites.
    The db is also equal (different only in the primary domain name of course) and permissions over files and directories also are ok on both sides.

    At this point i don't know where to look for a solution.

  11. sarett
    Member
    Posted 2 years ago #

    I forgot to mention that both sites are hosted on the same server under two different domains which i can create and manage through a plesk control panel.

  12. You did a total mimic right? All the sites and sub-sites?

  13. sarett
    Member
    Posted 2 years ago #

    Yes a total mimic one, all sites and subsites, the structure, users, posts, etc.

  14. Pull your .htaccess and make it the default one for WP Multisite?

  15. sarett
    Member
    Posted 2 years ago #

    I'm sorry but I don't think i have understood what you mean.

    My current .htaccess for wp multisite is the following:

    RewriteEngine On
    RewriteBase /blogs/
    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]
  16. That's the whole thing?

    Does it look the same as the test site? Except for the /blogs/ bit? :)

  17. sarett
    Member
    Posted 2 years ago #

    Yes, it does look the same, even the /blogs/ part is the same.

    I replicated the same identical structure in both the staging and the production site!

    In practice the sites are like this:
    STAGING:
    http://www.stagingurl.com -> main joomla site
    http://www.stagingurl.com/blogs/ -> main blog (id #1 in wordpress multisite)
    http://www.stagingurl.com/blogs/foo/ -> secondary blog (id #2)
    http://www.stagingurl.com/blogs/bar/ -> secondary blog (id #3)

    PRODUCTION:
    http://www.productionurl.com -> main joomla site
    http://www.productionurl.com/blogs/ -> main blog (id #1 in wordpress multisite)
    http://www.productionurl.com/blogs/foo/ -> secondary blog (id #2)
    http://www.productionurl.com/blogs/bar/ -> secondary blog (id #3)

  18. I'm unfamiliar with Joomla but is there a .htaccess file in the root where Joomla lives?

  19. sarett
    Member
    Posted 2 years ago #

    Yes Jan, of course there is and it's this one:

    ##
    # @package		Joomla
    # @copyright	Copyright (C) 2005 - 2012 Open Source Matters. All rights reserved.
    # @license		GNU General Public License version 2 or later; see LICENSE.txt
    ##
    
    ##
    # READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
    #
    # The line just below this section: 'Options +FollowSymLinks' may cause problems
    # with some server configurations.  It is required for use of mod_rewrite, but may already
    # be set by your server administrator in a way that dissallows changing it in
    # your .htaccess file.  If using it causes your server to error out, comment it out (add # to
    # beginning of line), reload your site in your browser and test your sef url's.  If they work,
    # it has been set by your server administrator and you do not need it set here.
    ##
    
    ## Can be commented out if causes errors, see notes above.
    Options +FollowSymLinks
    
    ## Mod_rewrite in use.
    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^productionurl\.com
    RewriteRule ^(.*)$ http://www.productionurl.com/$1 [R=permanent,L]
    
    ## Begin - Rewrite rules to block out some common exploits.
    # If you experience problems on your site block out the operations listed below
    # This attempts to block the most common type of exploit <code>attempts</code> to Joomla!
    #
    # Block out any script trying to base64_encode data within the URL.
    RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
    # Block out any script that includes a <script> tag in URL.
    RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
    # Block out any script trying to set a PHP GLOBALS variable via URL.
    RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
    # Block out any script trying to modify a _REQUEST variable via URL.
    RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
    # Return 403 Forbidden header and show the content of the root homepage
    RewriteRule .* index.php [F]
    #
    ## End - Rewrite rules to block out some common exploits.
    
    ## Begin - Custom redirects
    #
    # If you need to redirect some pages, or set a canonical non-www to
    # www redirect (or vice versa), place that code here. Ensure those
    # redirects use the correct RewriteRule syntax and the [R=301,L] flags.
    #
    ## End - Custom redirects
    
    ##
    # Uncomment following line if your webserver's URL
    # is not directly related to physical file paths.
    # Update Your Joomla! Directory (just / for root).
    ##
    
    # RewriteBase /
    
    ## Begin - Joomla! core SEF Section.
    #
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    #
    # If the requested path and file is not /index.php and the request
    # has not already been internally rewritten to the index.php script
    RewriteCond %{REQUEST_URI} !^/index\.php
    # and the request is for something within the component folder,
    # or for the site root, or for an extensionless URL, or the
    # requested URL ends with one of the listed extensions
    RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
    # and the requested path and file doesn't directly match a physical file
    RewriteCond %{REQUEST_FILENAME} !-f
    # and the requested path and file doesn't directly match a physical folder
    RewriteCond %{REQUEST_FILENAME} !-d
    # internally rewrite the request to the index.php script
    RewriteRule .* index.php [L]
    #
    ## End - Joomla! core SEF Section.

    It is located in the root of the site (i replaced the real domain name with the example one i used before of course) http://www.productionurl.com

  20. That shouldn't impact anything (I've done similar before).

    And it works in staging but not production, which really implies something isn't the same between the two :(

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.