Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write mod rewrite to serve @2x images from different path?
    text
    copied!<p>I am trying to use Drupal 7 to manage the content for an iOS app. I can setup Drupal to create retina (@2x) size and non-retina size images. Rather than update the app to get @2x images from a different path, I would like to use mod rewrite if possible to serve @2x images from a different folder.</p> <p>For example, the path to non-retina images are: &nbsp;&nbsp;&nbsp;&nbsp;/sites/default/files/styles/<code>large</code>/public/flyers/OfficialSchedule.jpg?itok=qGpDKWpr</p> <p>I would like the request for OfficialSchedule@2x.jpg to come from: &nbsp;&nbsp;&nbsp;&nbsp;/sites/default/files/styles/<code>retina</code>/public/flyers/OfficialSchedule.jpg?itok=qGpDKWpr</p> <p>Is this possible?</p> <p><em><strong>Result: Thanks to @jerdiggity</em></strong></p> <p>I had to add <code>$conf['image_allow_insecure_derivatives'] = TRUE;</code> to my settings file for Drupal 7.20 and higher to allow images to be requested without adding the token value.</p> <pre><code># NOTES: Check the file name to see if it matches the @2x pattern: RewriteCond %{REQUEST_FILENAME} ^(.*)(@2x\.\w+)$ [NC] # NOTES: This may or may not be necessary, depending on your desired results (uncomment if so): RewriteCond %{REQUEST_URI} ^(/sites/default/files/styles/regular/public/flyer/) [NC] # NOTES: Rewrite everything with @2x, but don't rewrite requests to the /sites/default/files/styles/retina/public/flyer/ directory (duplicate rewrites) RewriteCond %{REQUEST_URI} !^(/sites/default/files/styles/retina/public/flyer/) [NC] RewriteRule ([^/]*)@2x\.(\w+) /sites/default/files/styles/retina/public/flyer/$1\.$2 [L,R=301] </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload