htaccess redirects for images

Discussion in 'Site & Server Administration' started by dieselcatalog, Nov 24, 2008.

  1. #1
    Hello,

    I'm doing a major overhaul on a big website. The site has 1000's of images, and they are all in the root directory. I have copied and moved them to a directory called /images/, and plan on changing the image paths on as many pages as I can, but the images are used on several of their sister sites and they probably also get a ton of search engine traffic for those images. Is there a way to do something with htaccess to make it so when an image is pulled up in the root directory, that it looks for it in the "/images/" directory instead?

    Thanks,

    Andy
     
    dieselcatalog, Nov 24, 2008 IP
  2. dieselcatalog

    dieselcatalog Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm sorry, I should have put this in the Apache Section. I feel really really bad about that. I apologize.
     
    dieselcatalog, Nov 24, 2008 IP
  3. dieselcatalog

    dieselcatalog Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Here is what I found, but it is still not working:

    RewriteEngine On
    RewriteBase /
    
    # prevent endless loops
    RewriteCond %{REQUEST_URI} !images/
    
    # capture only the filename 
    RewriteRule ^.*/(.*\.jpg|.*\.gif|.*\.bmp) images/$1 [L,R]
    Code (markup):
    Any ideas?
     
    dieselcatalog, Nov 24, 2008 IP
  4. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #4
    This is the RewriteRule I would use.
    RewriteRule ^/?([^/]+)\.(jpe?g|gif|bmp|png)$ /images/$1.$2 [R=301]
    Code (markup):
    If there's no further rewrites needed within the /images/ directory, I'd turn off the rewriteengine in that directories htaccess to prevent double rewrite tests.
    RewriteEngine off
    Code (markup):
     
    joebert, Nov 24, 2008 IP
  5. SiteSeal-developer

    SiteSeal-developer Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Does anyone have and .htacsess code to protect images on a win32 server?
     
    SiteSeal-developer, Nov 24, 2008 IP