For an acute server crash problem, I'm trying to match any request for @2x retina style images, and rewrite it to the non-@2x equivalent.

First I want to check this is such a request:

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

For example:


Then I need to just take out @2x and return:


Could be png or jpeg or PNG or gif etc.

I'm no RegExp ninja. I know how to replace parts, but not remove. Can anyone please assist? My servers are dying because of 404's...

EDIT: Seems like it's:

RewriteCond %{REQUEST_FILENAME} ^(.*)(@2x\.\w+)$ [NC]
RewriteRule (.+)@2x\.(\w+)$ $1.$2 [R=302]


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.