John Davidson

Images not showing on my localhost with Docker php image (htaccess issue and adaptive-images tool)

0 comments
Message:


I have a problem with an old website that uses a php tool that adapts the images according to the resolution of the device. The tool is called adaptive-images, which has been dormant for many years, but still works fine.


Here is the github link to the tool:


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


apaptative-images.php


https://github.com/MattWilcox/Adaptive-Images/blob/master/adaptive-images.php


The problem is that I want to have that page locally to manage it and the images are not visible. I have always had the website locally with wamp (windows) and it has never given any problems, but now I want to do it with Linux and Docker (php+apache), but the images are not displayed and I think the problem may be due to the php configuration of the server. When I remove the adaptive-images part of the code from the .htaccess, the images load perfectly. This is the htaccess code:


# Adaptive-Images -----------------------------------------------------------------------------------

# Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows:
# RewriteCond %{REQUEST_URI} !some-directory
# RewriteCond %{REQUEST_URI} !another-directory

RewriteCond %{REQUEST_URI} !assets

# Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
# to adaptive-images.php so we can select appropriately sized versions

RewriteRule \.(?:jpe?g|png)$ adaptive-images.php

# END Adaptive-Images -------------------------------------------------------------------------------

I know there are newer tools (srcset) to do this (the same developer warns it in the documentation), but adaptive-images still works perfectly and I don't want to change it for now. It works on external servers without problems, also on wamp (Windows) with php 7.4, but in Docker's php-apache (version 8.1.5) it doesn't work and I think the problem could be in some php component. I can access all the php settings to change it, but I would like to know where the problem would be.


The Docker image I have installed (version 8.1.5):


https://hub.docker.com/_/php


EDIT:


I think I have identified the problem, it is when activating the mod-rewrite (I need it to load blog posts). If I activate it the images disappear. Can someone help me to identify the reason?


.htaccess:


  ## Default .htaccess file


<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On


RewriteBase /


RewriteRule ^sitemap.xml$ sitemap.php [L]

RewriteRule ^([^/]*)/$ /alone.php?url=$1 [L]


RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /alone\.php\?url=(.+)\ HTTP/
RewriteRule ^alone\.php$ /%1/? [L,R=301]


# Adaptive-Images -----------------------------------------------------------------------------------

# Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows:
# RewriteCond %{REQUEST_URI} !some-directory
# RewriteCond %{REQUEST_URI} !another-directory

RewriteCond %{REQUEST_URI} !assets

# Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
# to adaptive-images.php so we can select appropriately sized versions

RewriteRule \.(?:jpe?g|png)$ adaptive-images.php



# END Adaptive-Images -------------------------------------------------------------------------------



</IfModule>




<ifModule mod_gzip.c>

mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

When I remove the adaptive-images part of the htaccess it loads all the images, but of course the tool stops working.



My Answer:

# BEGIN Adaptive-Images

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/adaptive-images.php
RewriteCond %{HTTP_COOKIE} !^.*resolution= [NC]
RewriteRule (.*) adaptive-images.php/$1 [L]

# END Adaptive-Images


_It seems that the issue might be related to the RewriteRule in the .htaccess file. When the adaptive-images.php is called, it might not be properly redirecting the image requests to the adaptive-images tool. You can try modifying the RewriteRule to include the full path to the adaptive-images.php file like this:_


RewriteRule (.*) /path/to/adaptive-images.php/$1 [L]


_Make sure to replace `/path/to/adaptive-images.php` with the actual path to the adaptive-images.php file on your server. This should ensure that the image requests are properly redirected to the adaptive-images tool and the images are displayed correctly._

Rate this post

3 of 5 based on 9704 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us