Solved

URL rewrite image links

Posted on 2012-04-02
4
254 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 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 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

615 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