多条件RewriteRules htaccess

时间:2013-10-08 07:22:01

标签: wordpress .htaccess mod-rewrite retina

我在WordPress主题上使用Adaptive-Images,我想将一些正常比例图像重定向到双倍比例/尺寸图像,以支持HiDPI / Retina。但Adaptive-Images中的RewriteRule会覆盖HiDPI RewriteRule

两个脚本都可以很好地工作,但不能一起工作。 我可以通过Adaptive-Images从主RewriteRule中排除一些图像尺寸吗?或任何其他解决方案?

感谢
Ogni

我的.htaccess看起来像

<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>

1 个答案:

答案 0 :(得分:0)

您是否尝试过交换两条规则的顺序并在自适应图像规则中添加[L]标记?

<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>

似乎请求专门用于277x190大小的图像,因此HiDPI规则将首先匹配。否则,Adaptive规则将匹配。