Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

URL rewrite image links

Posted on 2012-04-02
4
Medium Priority
?
262 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 51

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 51

Accepted Solution

by:
Steve Bink earned 2000 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

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
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 …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month9 days, 20 hours left to enroll

926 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