Solved

URL rewrite image links

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

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…
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now