Solved

URL rewrite image links

Posted on 2012-04-02
4
224 Views
Last Modified: 2012-04-03
I have third party sites that link to some images on my site. The images were placed in Magento's image cache some time ago. But when the cache is refreshed, Magento modifies the file names and thus the links become unreachable. It is not every image just certain ones that this is happening to.

How can I modify my .htaccess to make the links go to a static copy of the image located in another directory?
0
Comment
Question by:EddieShipman
  • 2
  • 2
4 Comments
 
LVL 50

Expert Comment

by:Steve Bink
ID: 37799134
Something like this:

RewriteRule ^/?path/to/cache/(.+\.(png|jpg|gif))$ /path/to/static/$1 [NC]

Open in new window


You could also use a RewriteCond directive to isolate the referer.  If this is happening to several files, you might consider using a RewriteMap configuration for manageability.
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 37800662
I only want a certain 22 files redirected, the above does for all files in that path.
How would I use this RewriteMap?
0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 37802939
See the docs here:

http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritemap

RewriteMap is less than optimal for many people because it requires access to the server's conf files.  The map itself can be used in .htaccess, but it must be defined at the server/vhost level.  If you cannot use a RewriteMap configuration, your other alternative is to write rules for each file individually:

RewriteRule ^/?path/to/cache/image1\.png$ /path/to/static/image1.png [NC]
RewriteRule ^/?path/to/cache/image2\.png$ /path/to/static/image2.png [NC]
RewriteRule ^/?path/to/cache/imagen\.png$ /path/to/static/imagen.png [NC]

Open in new window

0
 
LVL 26

Author Closing Comment

by:EddieShipman
ID: 37803843
Actually ended up using redirect for all 23, thanks.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question