2

I am trying to incorporate Adaptive images - http://www.adaptive-images.com/ into my website.

Github account - https://github.com/MattWilcox/Adaptive-Images

Ideally the .htaccess should redirect all images to adaptive-images.php and the output should be resized images.

The images aren't loading. I checked the response headers and its returning text/html. It seems like the request is going to index.php file.

Below is the current .htaccess which i am using

<IfModule mod_rewrite.c>

  RewriteEngine On

  # Send any GIF, JPG, or PNG request that IS NOT stored inside ai-cache
  # to adaptive-images.php

  RewriteCond %{REQUEST_URI} !/ai-cache
  RewriteRule \.(jpe?g|gif|png)$ adaptive-images.php

  # Send all files except css, js or image files to index.php

  RewriteBase /
  RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
  RewriteRule ^.*$ index.php

</IfModule>

The first part is where I'm trying to make it work

The second part works perfectly.

1 Answer 1

1

You can change REQUEST_URI with THE_REQUEST that represents original Apache request and it doesn't change after application of other rules unlike REQUEST_URI.

DirectoryIndex index.php

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteBase /

  # Send any GIF, JPG, or PNG request that IS NOT stored inside ai-cache
  # to adaptive-images.php

  RewriteCond %{REQUEST_URI} !/ai-cache [NC]
  RewriteRule \.(jpe?g|gif|png)$ adaptive-images.php [L]

  # Send all files except css, js or image files to index.php

  RewriteCond %{THE_REQUEST} !(robots\.txt|\.(css|js|png|jpe?g|gif)) [NC]
  RewriteRule . index.php [L]

</IfModule>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks its working now. I have one more question - Since all files direct to index.php and onwards to a router - does the .htaccess need directives like prevent directory listing or prevent access to .htaccess. Should i still need to protect my .htaccess
Everything is already rewriting to index.php so you should be fine. But to be one safer side you can put Options -Indexes at the top to disallow directory listing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.