0

我正在尝试使用 Drupal 7 来管理 iOS 应用程序的内容。我可以设置 Drupal 来创建视网膜 (@2x) 大小和非视网膜大小的图像。与其更新应用程序以从不同的路径获取 @2x 图像,我想尽可能使用 mod rewrite 来提供来自不同文件夹的 @2x 图像。

例如,非视网膜图像的路径是:large/sites/default/files/styles//public/flyers/OfficialSchedule.jpg?itok=qGpDKWpr

我希望 OfficialSchedule@2x.jpg 的请求来自:/sites/default/files/styles/ retina/public/flyers/OfficialSchedule.jpg?itok=qGpDKWpr

这可能吗?

结果:感谢@jerdiggity

我必须$conf['image_allow_insecure_derivatives'] = TRUE;为 Drupal 7.20 及更高版本添加到我的设置文件中,以允许在不添加令牌值的情况下请求图像。

# 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]
4

1 回答 1

0

您应该能够通过使用文件位置的绝对路径来做到这一点......

这假设您的站点安装在/home/mydrupalsite

# NOTES: Check the file name to see if it matches the @2x pattern:
RewriteCond %{REQUEST_FILENAME} ^(.*)(@2x\.jpg)$ [NC]

# NOTES: This may or may not be necessary, depending on your desired results (uncomment if so):
# RewriteCond %{REQUEST_URI} ^(/sites/default/files/styles/large/public/flyers/) [NC]

# NOTES: Rewrite everything with @2x, but don't rewrite requests to the /sites/default/files/styles/retina/public/flyers/ directory (duplicate rewrites)
RewriteCond %{REQUEST_URI} !^(/sites/default/files/styles/retina/public/flyers/) [NC]
RewriteRule ^(.*)@2x\.jpg /home/mydrupalsite/sites/default/files/styles/retina/public/flyers/$1\.jpg [L,R=301]

希望对您有所帮助... :)

于 2013-05-24T21:00:46.423 回答