Solved

htaccess question

Posted on 2013-05-25
9
390 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
  • 5
  • 3
9 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 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 108

Expert Comment

by:Ray Paseur
ID: 39197169
If it comes to you from hielo it is better than acceptable -- it is good advice!
0
 

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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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 dynamically set the form action using jQuery.

911 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

20 Experts available now in Live!

Get 1:1 Help Now