?
Solved

htaccess question

Posted on 2013-05-25
9
Medium Priority
?
407 Views
Last Modified: 2013-05-26
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
0
Comment
Question by:ddantes
[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
  • 5
  • 3
9 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 2000 total points
ID: 39197050
The easiest approach would be to create an ".htaccess" file within your "Test" folder and create the rule there.

If you don't want to do that, assuming that adaptive-images.php is in the "Test" folder, try:
RewriteRule ^/?Test/.+\.(?:jpe?g|gif|png)$ /Test/adaptive-images.php

Open in new window

0
 

Author Comment

by:ddantes
ID: 39197067
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?
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39197169
If it comes to you from hielo it is better than acceptable -- it is good advice!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ddantes
ID: 39197177
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.
0
 
LVL 82

Expert Comment

by:hielo
ID: 39197207
>>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
0
 

Author Comment

by:ddantes
ID: 39197215
Very clear.  Thank you.
0
 

Author Comment

by:ddantes
ID: 39197218
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.
0
 
LVL 82

Expert Comment

by:hielo
ID: 39197564
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

0
 

Author Comment

by:ddantes
ID: 39198050
That's very helpful.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

801 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