How can I use .htaccess to load images from a different directory

Discussion in 'Site & Server Administration' started by jasonwilks, Jun 15, 2012.

  1. #1
    Hello, I have a site with many sub-directories, with only one location for the images in the home directory.

    The site uses include files loaded from the /includes folder in the root directory to construct the templates for every page in every directory (even for the sub-directories).

    Now the include files are calling for images in their main directory for each sub-directory. But the images are all located in the /images (home directory) of the site.

    I assume there has to be a way where I can use an .htaccess file to put in each sub-directory to relocate and load the images from the home directory for the sub-directories.

    What command line would I need to put in the .htaccess file to make this happen?

    If this sounds confusing to you, then this is an example:

    This is what my site structure looks like:

    /images
    /includes
    /websitefile.php
    /websitefile.php
    /subdirectory1/websitefile.php --The include code inside these look like this: <?php include("../includes/template-a.htm"); ?> (inside these include files images are being called like this: /images/picture.jpg)
    /subdirectory2/websitefile.php
    /subdirectory3/websitefile.php
    /subdirectoryetc/websitefile.php

    Now all these websitefiles are calling for the images in their main directory. The websitefiles in the root directory load the images fine, but the websitefiles in the sub-directories are not loading right now (because all the images are located in the parent directory!)

    See what I mean? So what would i need to put in the .htaccess to make the images load up for the sub-directories?

    Thank You!
     
    Last edited: Jun 15, 2012
    jasonwilks, Jun 15, 2012 IP
  2. jasonwilks

    jasonwilks Well-Known Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    111
    #2
    Nevermind I figured out an easy workaround to this. All I had to do is use the FULL URL to the images in the include files instead of using /images/picture.jpg

    duh :)
     
    jasonwilks, Jun 15, 2012 IP