Question

I'm using Adaptive-Images on a WordPress Theme and I'd like to redirect some normal ratio images to double ratio/size images for HiDPI/Retina support, too. But the RewriteRule from Adaptive-Images will override the HiDPI RewriteRule.

Both Scripts works alone well, but not together. Can I exclude some image sizes from the main RewriteRule by Adaptive-Images? Or any other solution?

Thanks
Ogni

My .htaccess looks like

<IfModule mod_rewrite.c>
RewriteEngine On

# Adaptive-Images
# http://adaptive-images.com
RewriteCond %{REQUEST_URI} cms/assets
RewriteRule \.(?:jpe?g|gif|png)$ cms/wp-content/themes/roots/inc/adaptive-images.php

# HiDPI
# http://cup.wpcoder.de/wordpress-hidpi-bilder/ 
RewriteCond %{HTTP_COOKIE} HTTP_IS_HIDPI
RewriteCond %{DOCUMENT_ROOT}/$1-554x380.$2 -f
RewriteRule ^(cms/assets.+)-277x190\.(jpe?g|png)$ $1-554x380.$2 [L] 

</IfModule>
Was it helpful?

Solution

Have you tried swapping the order of the two rules and adding a [L] flag to the adaptive images rule?

<IfModule mod_rewrite.c>
RewriteEngine On

# prevent any looping
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

# HiDPI
# http://cup.wpcoder.de/wordpress-hidpi-bilder/ 
RewriteCond %{HTTP_COOKIE} HTTP_IS_HIDPI
RewriteCond %{DOCUMENT_ROOT}/$1-554x380.$2 -f
RewriteRule ^(cms/assets.+)-277x190\.(jpe?g|png)$ $1-554x380.$2 [L] 

# Adaptive-Images
# http://adaptive-images.com
RewriteCond %{REQUEST_URI} cms/assets
RewriteRule \.(?:jpe?g|gif|png)$ cms/wp-content/themes/roots/inc/adaptive-images.php [L]

</IfModule>

It seems like if the request is specifically for 277x190 sized images, the HiDPI rules will therefore match first. Otherwise, the Adaptive rule will match.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top