Link to home
Start Free TrialLog in
Avatar of ddantes
ddantesFlag for United States of America

asked on

htaccess question

I'm experimenting with an adaptive image solution which refers image requests to a php file, and serves an image size which is appropriate to the user's device.  I'm trying to conduct this test in a subfolder of my server root directory, so I initially placed the htaccess file and the php file in that directory.  It doesn't work, unless both those files reside in the root directory.  But, if those files reside in the root directory, my "experiment" is applied to my existing website, not just the contents of the testing folder.  htaccess allows for code which excludes folders, but I don't know what syntax to use in order to apply it only to a specified subfolder. Is there a way I can have htaccess in the root directory, and have it apply only to a subfolder, such as "Test"?  I've attached the text for htaccess.htaccess-text.txt
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ddantes

ASKER

Thank you.  I placed the htaccess file and the php in the "Test" folder, and modified the php file with this path to the image cache folder:  "Test/ai-cache".   It seems to work now.  Do you think this is acceptable?
If it comes to you from hielo it is better than acceptable -- it is good advice!
Avatar of ddantes

ASKER

Thank you.  For clarification, I wasn't asking of hielo's advice was acceptable.  I was asking if my editing in the php file, with respect to the path to the ai-cache folder, was acceptable.
>>and modified the php file with this path to the image cache folder:  "Test/ai-cache"
This is a matter of preference.  It is certainly not "unacceptable".  By setting $cache_path    = "Test/ai-cache" you have basically "confined" all these "testing" resized images to the "site.com/Test/ai-cache" folder, but it shouldn't have any negative impact if you were to leave it as "ai-cache".  If you leave it as "ai-cache", all the test image would be "confined" to "site.com/ai-cache".  So, to answer you question directly, your change is acceptable.  But even if you had chosen not to make the change, it would be acceptable as well.

Regards,
Hielo
Avatar of ddantes

ASKER

Very clear.  Thank you.
Avatar of ddantes

ASKER

I've closed this question, but if you're willing, I have an additional query...
I have many images which are 1000px or wider.  But only images of around 1400px or greater have been cached during this test, so far.  I've loaded images on a desktop, including with resolution set to 800 x 600, as well as on an iPad and iPhone (both with retina display).  I was expecting many of my images would be cached at different break points, that didn't happen.  Is that to be expected?  If so, I'm wondering what the value of this solution might be.
To "demystify" this issue, you may need to figure out what is the computed value of $resolution for your various test cases.  If you look at the code around line 143, you will find:
  // Do we need to downscale the image?
  if ($width <= $resolution) { // no, because the width of the source image is already less than the client width
    return $source_file;
  }

Open in new window


but the value of $resolution is computer between lines 244-295 and your "expected" value may change, depending on $pixel_density.
        // now apply the multiplier
        $resolution = $resolution * $pixel_density;

Open in new window


Also notice that now there is a cookie-dependency:
http://adaptive-images.com/download.htm

Thus, if there is no cookie upon first visit the following will happen:
/* No resolution was found (no cookie or invalid cookie) */
if (!$resolution) {
  // We send the lowest resolution for mobile-first approach, and highest otherwise
  $resolution = $is_mobile ? min($resolutions) : max($resolutions);
}

Open in new window

Avatar of ddantes

ASKER

That's very helpful.