Solved

htaccess question

Posted on 2013-05-25
9
396 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 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 110

Expert Comment

by:Ray Paseur
ID: 39197169
If it comes to you from hielo it is better than acceptable -- it is good advice!
0
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.

 

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

Don't miss ATEN at NAB Show April 24-27!

Visit ATEN at NAB Show to learn how our "Seamlessly Entertaining" solutions deliver fast, precise video streaming without delays for the broadcasting and media environment. ATEN will showcase its 16x16 Modular Matrix Switch (VM1600) and KVM Over IP Solution (KE6900 series).

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
replacing inline javascript with jquery 4 46
How do use '  ' within this code? 4 29
Put POST values into cookies. 14 35
Add - in a loop to first and last element. 6 43
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

730 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