• Resolved landwire

    (@landwire)


    Hi there,
    I am using a bedrock setup for wordpress and use the following filters to point to the correct directories:

    add_filter('webpc_uploads_path', function($path) {
        return '../app/uploads/';
    });

    This ‘webpc_uploads_path’ works as expected and the warning I had went away.

    But the following one does not seem to work. The files get created in the ‘uploads’ folder and not the ‘uploads-webpc’ folder.

    add_filter('webpc_uploads_webp', function($path) {
        return '../app/uploads-webpc/';
    });

    In the .htaccess file the section looks like this:

    # BEGIN WebP Converter
    <IfModule mod_mime.c>
      AddType image/webp .webp
    </IfModule>
    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/wp/../app/uploads-webpc/$1.jpg.webp -f
      RewriteRule ../app/uploads/(.+)\.jpg$ ../app/uploads-webpc/$1.jpg.webp [T=image/webp]
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/wp/../app/uploads-webpc/$1.jpeg.webp -f
      RewriteRule ../app/uploads/(.+)\.jpeg$ ../app/uploads-webpc/$1.jpeg.webp [T=image/webp]
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/wp/../app/uploads-webpc/$1.png.webp -f
      RewriteRule ../app/uploads/(.+)\.png$ ../app/uploads-webpc/$1.png.webp [T=image/webp]
    </IfModule>
    <IfModule mod_expires.c>
      ExpiresActive On
      ExpiresByType image/webp "access plus 1 year"
    </IfModule>
    # END WebP Converter

    Maybe we need a filter to define ABSPATH in a different way, so I do not need to use the ../? My webrooot is web. ABSPATH will point to web/wp/. But my uploads folder is in web/app/

    web
      /app
        /uploads
        /plugins
        /themes
        ...
      /wp
        /wp-admin
        ...
    • This topic was modified 5 years ago by landwire.
Viewing 14 replies - 1 through 14 (of 14 total)
  • Thread Starter landwire

    (@landwire)

    1. Does your server meet the technical requirements described in the FAQ?
    YES

    2. Do you use CDN? If so, please see the question “Does the plugin support CDN?” in plugin FAQ.
    NO

    3. Do you use other plugins to optimize images? Please disable them and check this plugin without them. Remember not to combine several optimization plugins because they can be mutually exclusive.
    NO

    4. Check if in /wp-content/uploads-webpc/ directory are all files that should be converted.
    NO -> SEE COMMENT ABOVE
    NO ERRORS IN THE CONSOLE

    5. URL of your website. If your site is not publicly available, add it to test environment.
    JUST LOCAL ENVIRONMENT AT THE MOMENT

    6. Configuration of your server (link to it can be found on the settings page of plugin in the section “We are waiting for your message”) – please take a screenshot of the ENTIRE page and send it to me.
    SEEMS OK

    7. Content of your .htaccess file.
    SEE ABOVE -> THIS IS NOT THE PROBLEM AT THE MOMENT

    8. What plugin version are you using? If it is not the latest then update and check everything again. Please also provide the version of WordPress and the list of plugins you use.
    LATEST VERSION OF THE PLUGIN

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @landwire,

    Thank you for your message.

    I’m afraid that the problem will be the handling of ../ characters. Is there any way to get access to the web server path?

    Thread Starter landwire

    (@landwire)

    Hi Mateusz,
    not sure if I understand your question correct.

    But I could set a WP Constant in my config to give the webroot for instance:

    /**
     * Define WEBROOT
     */
    if (!defined('WEBROOT')) {
        define('WEBROOT', $webroot_dir );
    }

    And this is the absolute path:
    /var/www/html/bedrock/web/

    And this the value of the ABSPATH variable:
    /var/www/html/bedrock/web/wp/

    Uploads are located here:
    /var/www/html/bedrock/web/app/uploads

    But your plugin uses ABSPATH in Errors.php and therefore I get an error shown:
    Server configuration error
    The path for uploads files does not exist. Please use the webpc_uploads_path filter to set the correct path. The default path is: /var/www/html/bedrock/web/wp/wp-content/uploads/.

    I would think you need to add a filter somewhere so I can change the actual path to the uploads folder independent of the ABSPATH. But I am not sure…

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @landwire, Thank you for your waiting time. I am currently working on a new version of the plugin.

    I added the webpc_uploads_root filter to it, which returns ABSPATH by default, but you can change it and set your own.

    Could you test it? Here you will find the beta version: https://gbiorczyk.pl/webp-converter-for-media-v1.1.3.zip

    I would be grateful if you could respond quickly.

    Thread Starter landwire

    (@landwire)

    Hello Mateusz,
    thank you!

    Sorry, I could not get to it before this morning.

    That all works fine now with the folders.
    But there is nothing written to the .htaccess file and therefore it does not work at the moment. If you look above, I did have some entries in the .htaccess file before your changes.

    I do not mind adding it by hand if you let me know what needs to go in there. Just to see if it generally works.

    Any ideas?

    • This reply was modified 4 years, 11 months ago by landwire.
    • This reply was modified 4 years, 11 months ago by landwire.
    Thread Starter landwire

    (@landwire)

    I tried to do it by hand and this is my full .htaccess file, but it does not seem to work yet.

    
    
    # BEGIN All In One WP Security
    #AIOWPS_BLOCK_WP_FILE_ACCESS_START
    <Files license.txt>
    <IfModule mod_authz_core.c>
    Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
    </IfModule>
    </Files>
    <Files wp-config-sample.php>
    <IfModule mod_authz_core.c>
    Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
    </IfModule>
    </Files>
    <Files readme.html>
    <IfModule mod_authz_core.c>
    Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
    </IfModule>
    </Files>
    #AIOWPS_BLOCK_WP_FILE_ACCESS_END
    #AIOWPS_BASIC_HTACCESS_RULES_START
    <Files .htaccess>
    <IfModule mod_authz_core.c>
    Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
    </IfModule>
    </Files>
    ServerSignature Off
    LimitRequestBody 10485760
    <Files wp-config.php>
    <IfModule mod_authz_core.c>
    Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
    </IfModule>
    </Files>
    #AIOWPS_BASIC_HTACCESS_RULES_END
    #AIOWPS_PINGBACK_HTACCESS_RULES_START
    <Files xmlrpc.php>
    <IfModule mod_authz_core.c>
    Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
    </IfModule>
    </Files>
    #AIOWPS_PINGBACK_HTACCESS_RULES_END
    #AIOWPS_DEBUG_LOG_BLOCK_HTACCESS_RULES_START
    <Files debug.log>
    <IfModule mod_authz_core.c>
    Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
    </IfModule>
    </Files>
    #AIOWPS_DEBUG_LOG_BLOCK_HTACCESS_RULES_END
    # END All In One WP Security
    
    # BEGIN WordPress
    # The directives (lines) between <code>BEGIN WordPress</code> and <code>END WordPress</code> are
    # dynamically generated, and should only be modified via WordPress filters.
    # Any changes to the directives between these markers will be overwritten.
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress
    
    # BEGIN WebP Converter
    <IfModule mod_mime.c>
      AddType image/webp .webp
    </IfModule>
    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/app/uploads-webpc/$1.jpg.webp -f
      RewriteRule uploads/(.+)\.jpg$ uploads-webpc/$1.jpg.webp [T=image/webp]
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/app/uploads-webpc/$1.jpeg.webp -f
      RewriteRule uploads/(.+)\.jpeg$ uploads-webpc/$1.jpeg.webp [T=image/webp]
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/app/uploads-webpc/$1.png.webp -f
      RewriteRule uploads/(.+)\.png$ uploads-webpc/$1.png.webp [T=image/webp]
    </IfModule>
    <IfModule mod_expires.c>
      ExpiresActive On
      ExpiresByType image/webp "access plus 1 year"
    </IfModule>
    # END WebP Converter
    
    Thread Starter landwire

    (@landwire)

    Oh, sorry looked at the wrong .htaccess file. So this is the content of the one in the uploads folder:

    
    # BEGIN WebP Converter
    # ! --- DO NOT EDIT PREVIOUS LINE --- !
    <IfModule mod_mime.c>
      AddType image/webp .webp
    </IfModule>
    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/wp/uploads-webpc/$1.jpg.webp -f
      RewriteRule (.+)\.jpg$ /wp/uploads-webpc/$1.jpg.webp [T=image/webp]
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/wp/uploads-webpc/$1.jpeg.webp -f
      RewriteRule (.+)\.jpeg$ /wp/uploads-webpc/$1.jpeg.webp [T=image/webp]
      RewriteCond %{HTTP_ACCEPT} image/webp
      RewriteCond %{DOCUMENT_ROOT}/wp/uploads-webpc/$1.png.webp -f
      RewriteRule (.+)\.png$ /wp/uploads-webpc/$1.png.webp [T=image/webp]
    </IfModule>
    <IfModule mod_expires.c>
      ExpiresActive On
      ExpiresByType image/webp "access plus 1 year"
    </IfModule>
    # ! --- DO NOT EDIT NEXT LINE --- !
    # END WebP Converter
    

    So it still has the wrong paths with “wp” in there!

    Thread Starter landwire

    (@landwire)

    Ok, I changed those by hand. It seems to load the correct files as the file size is much smaller, though Chrome still shows them as jpeg. No idea why that is the case.
    See response headers below before and after. Size changed and the date changed too. Size corresponds to the jpeg and the webp.

    Before:

    
    accept-ranges: bytes
    content-length: 617734
    content-type: image/jpeg
    date: Sun, 22 Mar 2020 08:07:29 GMT
    etag: "96d06-5998220ae22bf"
    last-modified: Thu, 12 Dec 2019 13:57:36 GMT
    server: nginx/1.17.0
    status: 200
    

    After:

    
    accept-ranges: bytes
    content-length: 116058
    content-type: image/jpeg
    date: Sun, 22 Mar 2020 08:12:02 GMT
    etag: "1c55a-5a159e550679a"
    last-modified: Sat, 21 Mar 2020 09:19:14 GMT
    server: nginx/1.17.0
    status: 200
    vary: Accept
    
    Thread Starter landwire

    (@landwire)

    Ok, in case anyone has the same problem:
    Adding the mime type to the apache conf (/etc/apache2/conf-enabled/mime.conf) with AddType image/webp .webp solved my problem of not showing the correct type.
    No idea why it would ignore the directive from the .htaccess file, but I had the same problem an my local dev environment and on the live server.

    Thread Starter landwire

    (@landwire)

    So something inside Htaccess.php in line 55 and 56 still needs to be adjusted, then the .htaccess rules will be correct too:

    
    $path  = parse_url(site_url('/'), PHP_URL_PATH);
    $path .= apply_filters('webpc_uploads_webp', '', true);
    
    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @landwire, In the new version, the .htacces file is only generated in the /uploads/ directory. Rules have been deleted in the root directory.

    Using the filter below you have changed the root directory path:

    add_filter('webpc_uploads_root', function($path)
    {
      return WEBROOT;
    });

    Then to change the paths themselves, please use filters:

    add_filter('webpc_uploads_path', function($path)
    {
      return 'app/uploads;
    });

    and:

    add_filter('webpc_uploads_webp', function($path)
    {
      return 'app/uploads-webpc';
    });

    This should work for you. Could you check it out? To this filter setting, turn the plug off and on again. .htaccess files should be overwritten.

    Please do not edit the .htaccess files manually as these changes will be lost when the plugin is updated.

    As for displaying files in Dev Tools, in FA you have information that the plugin does not change the real address to the files. It will always display as JPEG, and yet it is a WebP file. This is the whole idea of ??this plugin.

    Thread Starter landwire

    (@landwire)

    Ok, I found the problem. Since bedrock by default puts the admin area under https://example.com/wp/wp-admin/, the value of parse_url(site_url(‘/’), PHP_URL_PATH); is /wp/. So the entries all are like;
    RewriteCond %{DOCUMENT_ROOT}/wp/app/uploads-webpc/$1.jpg.webp -f
    but should be:
    RewriteCond %{DOCUMENT_ROOT}/app/uploads-webpc/$1.jpg.webp -f

    Could you add the following filter $path = apply_filters('webpc_site_url_path', $path); to Htaccess.php to solve this problem?

    
          $path  = parse_url(site_url('/'), PHP_URL_PATH);
          $path = apply_filters('webpc_site_url_path', $path);
          $path .= apply_filters('webpc_uploads_webp', '', true);
    

    My entries in functions.php now look like this:

    
    add_filter('webpc_uploads_root', function($path) {
        return WEBROOT;
    });
    
    add_filter('webpc_site_url_path', function($path) {
        return '/';
    });
    
    add_filter('webpc_uploads_path', function($path) {
        return 'app/uploads';
    });
    
    add_filter('webpc_uploads_webp', function($path) {
        return 'app/uploads-webpc';
    });
    
    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Please download the new plugin version here again:
    https://gbiorczyk.pl/webp-converter-for-media-v1.1.3.zip

    And use the following filters (I added one new):

    add_filter('webpc_uploads_root', function($path) {
        return WEBROOT;
    });
    
    add_filter('webpc_site_url_path', function($path) {
        return '/';
    });
    
    add_filter('webpc_uploads_path', function($path) {
        return 'app/uploads';
    });
    
    add_filter('webpc_uploads_webp', function($path) {
        return 'app/uploads-webpc';
    });
    
    add_filter('webpc_uploads_prefix', function($prefix) {
        return '/';
    });
    Thread Starter landwire

    (@landwire)

    Works perfect.
    Thank you!
    Could you publish the updates on www.ads-software.com?

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Files created in uploads folder’ is closed to new replies.