Solved

htaccess question

Posted on 2013-05-25
9
387 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

757 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

21 Experts available now in Live!

Get 1:1 Help Now