Solved

URL rewrite image links

Posted on 2012-04-02
4
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

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). #…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …

752 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