• Resolved Adam

    (@dannythedog)


    add_filter( 'webpc_htaccess_mod_rewrite', function ( $rules ) {
    	return preg_replace(
    		'/(RewriteCond %{HTTP_ACCEPT} image\/(?:[a-z]+))/',
    		'$1' . PHP_EOL . '  RewriteCond %{QUERY_STRING} !(^|&)' . 'nocache' . ' [NC]',
    		$rules
    	);
    } );

    I’m using the above snippet to download original files from media using suffix ?nocache .

    On nginx server it doesn’t work. Is there any alternative method?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @dannythedog,

    Thank you for your message.

    You are right, this definitely won’t work on an Nginx server because the rules in the .htaccess file are not supported by the Nginx server. Once you install the plugin on the Nginx server, you need to add the following rules to the Nginx configuration – you have probably already done this.

    For what you want to do to work, find this fragment in the Nginx configuration::

    set $ext_avif ".avif";
    if ($http_accept !~* "image/avif") {
        set $ext_avif "";
    }
     
    set $ext_webp ".webp";
    if ($http_accept !~* "image/webp") {
        set $ext_webp "";
    }

    And replace it with this:

    set $ext_avif ".avif";
    if ($http_accept !~* "image/avif") {
        set $ext_avif "";
    }
     
    set $ext_webp ".webp";
    if ($http_accept !~* "image/webp") {
        set $ext_webp "";
    }
    
    if ($request_uri !~* "\?original") {
        set $ext_webp "";
        set $ext_avif "";
    }

    Then just add the ?original suffix to the image URL and you will always receive the original image.

    Best,
    Mateusz

    Thread Starter Adam

    (@dannythedog)

    Thank you for your help. Something strange happened and without the above-mentioned change in nginx.conf, after switching to wp-admin I have access to the original files, and from the front I have .webp servers. Weird but it works ??

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @dannythedog Our plugin does not change URLs to images, so when looking at the source of the website, you will see the URLs for the default images all the time. The plugin creates redirections to output files in WebP and AVIF format, changing the MIME type of these images, but without changing the URL.

    Considering the above, what you wrote is not possible. It doesn’t matter whether you upload the file on the front-end or in the WordPress dashboard.

    Additionally, you should not make changes to the nginx.conf file, only to the Nginx configuration file responsible for the selected host. The nginx.conf file is responsible for the general Nginx configuration.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Downloading orginal image file using ?nocache (nginx)’ is closed to new replies.