Nginx Rewrite Rule for Shopp Images

Summary

Since nginx does’t use .htaccess rules like Apache does, you have to do a little extra configuring to get nginx to route pretty URL image requests through Shopp’s built-in image server.

Generally, this configuration is only required when you are using pretty URLs, not the WordPress default URLs which will route through WordPress and the Shopp plugin. However, even with default URLs, adding a rewrite will vastly improve performance as it will avoid needing to load the entire WordPress stack (the theme and all active plugins) before handling the image request.

The rewrite shortcuts all of that and loads only what is absolutely necessary to provide the requested image. This results in massive response time savings, bringing a 1 second request down to a few hundred milliseconds.

Fix

These rewrite directives should go in the nginx config server { … } block for each Shopp site.

For Shopp 1.2:

location ~ /shop/images/(?<image>\d+)/? {
    rewrite ^ /wp-content/plugins/shopp/core/image.php?siid=$image; 
}

Credit to Blair Williams for figuring this out.

For Shopp 1.3:

location ~ /shop/images/(?<image>\d+)/? {
    rewrite ^ /wp-content/plugins/shopp/services/image.php?siid=$image; 
}

Notes

Be aware that some of the paths above can change depending on your hosting configuration and Shopp settings.

The location pattern can change if you have changed the slug for your main storefront page (the catalog landing page). By default Shopp uses the shop slug, however if you change it to something else, like store you’ll want to adjust the pattern: /store/images/(?<image>\d+)/?

You could just use /images/(?<image>\d+)/? instead if you are sure nothing else on your site has /images/ in the URL that should not go through the Shopp image server. If you have a separate directory under your web root say for /gallery/images then using /images/ in the Shopp image server location directive will cause the request to redirect to the Shopp image server.

Lastly, note that the path to the Shopp image server may be different than what is shown in the examples above. If you use a different directory for /wp-content or use a sub-directory install of WordPress, but still use the wp-content directory within it, you’ll need to adjust the path to image.php accordingly.

For example, with a sub-directory WordPress install under web root in a directory named wordpress/ and Shopp is installed in the wordpress/wp-content/plugins directory, you’ll need to adjust the rewrite path to: /wp-content/plugins/shopp/services/image.php?siid=$image;

See Also

Nginx Rewrite Rule for Shopp Images
  • 5.00 / 5 5
  1. Avatar of Annette

    This seems to no longer work with Shopp 1.3. Can anyone determine what changed?

    December 22nd   #

  2. Avatar of Doug

    Note that you must have your storage directories correctly defined before the rewrite rule will work. See https://shopplugin.net/kb/find-full-file-path/ and verify that your image paths are correct.

    March 20th   #

  3. Avatar of Doug

    Also, if your NGINX vhosts file includes multiple “location” blocks, you’ll want to put the one for images early in the file so it takes precedence over the other rewrite rules.

    Another trick that helped: sometimes it seems WordPress needs to be jostled by changing your permalink settings, e.g. by changing them to the default, saving them, and then changing them back. That fixed some of the 404 errors I was having.

    March 20th   #

You must be logged in to post a comment.

© Ingenesis Limited. Shopp™ is a registered trademark of Ingenesis Limited.

Skip to toolbar