shinsenter / php

📦 Simplified PHP Docker images for effortless customization and extension setup. Our Docker images cover PHP versions from 5.6 to 8.4, available in CLI, ZTS, FPM, FPM/Apache2, FPM/Nginx, RoadRunner, FrankenPHP, and Nginx Unit variants, for both Debian and Alpine versions. Updated everyday.
https://hub.docker.com/r/shinsenter/php
GNU General Public License v3.0
165 stars 26 forks source link

not reading .htaccess correctly #145

Closed NazgulCoder closed 2 months ago

NazgulCoder commented 2 months ago

Hello, and thank you for sharing your PHPFPM Apache container, is very useful and easy to setup.

I'm using your 7.4 or 8.0 phpfpm-apache alpine.

I'm encountering few issues with the rewrite mod though.

This .htaccess can be read only partially, I mean, rewrite conditions for the index.php works fine, other php pages don't get rewritten correctly.

Options -Indexes
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^search/(.*)/(.*)/ search.php?searchString=$1&max=$2
RewriteRule ^search/(.*)/(.*) search.php?searchString=$1&max=$2

RewriteRule ^search/(.*)/ index.php?p=items&searchString=$1
RewriteRule ^search/(.*) index.php?p=items&searchString=$1

RewriteRule ^items/(.*)/ index.php?p=items&id=$1
RewriteRule ^items/(.*) index.php?p=items&id=$1

RewriteRule ^items/ index.php?p=items
RewriteRule ^items index.php?p=items

RewriteRule ^user/(.*)/(.*)/ index.php?p=$1&n=$2
RewriteRule ^user/(.*)/(.*) index.php?p=$1&n=$2

RewriteRule ^user/(.*)/ index.php?p=$1
RewriteRule ^user/(.*) index.php?p=$1

RewriteRule ^home/ index.php
RewriteRule ^home index.php

RewriteRule ^logout/ index.php?p=logout
RewriteRule ^logout index.php?p=logout

RewriteRule ^wheel/(.*)/(.*)/ index.php?p=wheel&action=$1&key=$2
RewriteRule ^wheel/(.*)/(.*) index.php?p=wheel&action=$1&key=$2
RewriteRule ^wheel/(.*)/ index.php?p=wheel&action=$1
RewriteRule ^wheel/(.*) index.php?p=wheel&action=$1
RewriteRule ^wheel/ index.php?p=wheel
RewriteRule ^wheel index.php?p=wheel

RewriteRule ^javascript/(.*)/(.*)/(.*)/(.*)/ index.php?p=javascript&type=$1&id=$2&new=$3&friend=$4
RewriteRule ^javascript/(.*)/(.*)/(.*)/(.*) index.php?p=javascript&type=$1&id=$2&new=$3&friend=$4
RewriteRule ^javascript/(.*)/(.*)/(.*)/ index.php?p=javascript&type=$1&id=$2&new=$3
RewriteRule ^javascript/(.*)/(.*)/(.*) index.php?p=javascript&type=$1&id=$2&new=$3
RewriteRule ^javascript/(.*)/(.*)/ index.php?p=javascript&type=$1&id=$2
RewriteRule ^javascript/(.*)/(.*) index.php?p=javascript&type=$1&id=$2

RewriteRule ^admin/add/item/(.*)/(.*)/(.*)/ admin.php?a=item&id=$1&type=$2&wheel_level=$3
RewriteRule ^admin/add/item/(.*)/(.*)/(.*) admin.php?a=item&id=$1&type=$2&wheel_level=$3
RewriteRule ^admin/add/item/(.*)/(.*)/ admin.php?a=item&id=$1&type=$2
RewriteRule ^admin/add/item/(.*)/(.*) admin.php?a=item&id=$1&type=$2
RewriteRule ^admin/add/item/ admin.php?a=item
RewriteRule ^admin/add/item admin.php?a=item

RewriteRule ^admin/items/edit/(.*)/ admin.php?a=edit&id=$1
RewriteRule ^admin/items/edit/(.*) admin.php?a=edit&id=$1

RewriteRule ^admin/history/(.*)/(.*)/ admin.php?a=history&n=$1&s=$2
RewriteRule ^admin/history/(.*)/(.*) admin.php?a=history&n=$1&s=$2
RewriteRule ^admin/history/(.*)/ admin.php?a=history&n=$1
RewriteRule ^admin/history/(.*) admin.php?a=history&n=$1
RewriteRule ^admin/history/ admin.php?a=history
RewriteRule ^admin/history admin.php?a=history

RewriteRule ^admin/payments/list/(.*)/(.*)/ admin.php?a=list&n=$1&s=$2
RewriteRule ^admin/payments/list/(.*)/(.*) admin.php?a=list&n=$1&s=$2
RewriteRule ^admin/payments/list/(.*)/ admin.php?a=list&n=$1
RewriteRule ^admin/payments/list/(.*) admin.php?a=list&n=$1
RewriteRule ^admin/payments/list/ admin.php?a=list
RewriteRule ^admin/payments/list admin.php?a=list

RewriteRule ^admin/wheel/items/(.*)/(.*)/ admin.php?a=w_items&remove=$1&tab=$2
RewriteRule ^admin/wheel/items/(.*)/(.*) admin.php?a=w_items&remove=$1&tab=$2
RewriteRule ^admin/wheel/items/(.*)/ admin.php?a=w_items&remove=$1
RewriteRule ^admin/wheel/items/(.*) admin.php?a=w_items&remove=$1
RewriteRule ^admin/wheel/items/ admin.php?a=w_items
RewriteRule ^admin/wheel/items admin.php?a=w_items
RewriteRule ^admin/wheel/settings/ admin.php?a=w_settings
RewriteRule ^admin/wheel/settings admin.php?a=w_settings

RewriteRule ^admin/payments/settings/ admin.php?a=payments
RewriteRule ^admin/payments/settings admin.php?a=payments

RewriteRule ^admin/(.*)/(.*)/ admin.php?a=$1&n=$2
RewriteRule ^admin/(.*)/(.*) admin.php?a=$1&n=$2
RewriteRule ^admin/(.*)/ admin.php?a=$1
RewriteRule ^admin/(.*) admin.php?a=$1
RewriteRule ^admin/ admin.php
RewriteRule ^admin admin.php

In fact, I have another website with this .htaccess that doesn't have any problem at all

Options +FollowSymLinks
RewriteEngine On

<FilesMatch "\.csv$">
  Order deny,allow
  Deny from all
</FilesMatch>

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^users/register/(.*)/ index.php?p=register&ref=$1
RewriteRule ^users/register/(.*) index.php?p=register&ref=$1
RewriteRule ^users/register ./index.php?p=register
RewriteRule ^users/login ./index.php?p=login
RewriteRule ^users/logout ./index.php?p=logout
RewriteRule ^users/lost/(.*)/(.*)/ ./index.php?p=lost&email=$1&code=$2
RewriteRule ^users/lost/(.*)/(.*) ./index.php?p=lost&email=$1&code=$2
RewriteRule ^users/lost ./index.php?p=lost

RewriteRule ^news/(.*)/ index.php?page_no=$1
RewriteRule ^news/(.*) index.php?page_no=$1
RewriteRule ^news/ index.php
RewriteRule ^news index.php

RewriteRule ^read/(.*)/ index.php?p=read&no=$1
RewriteRule ^read/(.*) index.php?p=read&no=$1

RewriteRule ^ranking/players/(.*)/(.*)/ index.php?p=players&page_no=$1&player_name=$2
RewriteRule ^ranking/players/(.*)/(.*) index.php?p=players&page_no=$1&player_name=$2
RewriteRule ^ranking/players/(.*)/ index.php?p=players&page_no=$1
RewriteRule ^ranking/players/(.*) index.php?p=players&page_no=$1
RewriteRule ^ranking/players/ index.php?p=players
RewriteRule ^ranking/players index.php?p=players

RewriteRule ^ranking/guilds/(.*)/(.*)/ index.php?p=guilds&page_no=$1&guild_name=$2
RewriteRule ^ranking/guilds/(.*)/(.*) index.php?p=guilds&page_no=$1&guild_name=$2
RewriteRule ^ranking/guilds/(.*)/ index.php?p=guilds&page_no=$1
RewriteRule ^ranking/guilds/(.*) index.php?p=guilds&page_no=$1
RewriteRule ^ranking/guilds/ index.php?p=guilds
RewriteRule ^ranking/guilds index.php?p=guilds

RewriteRule ^user/delete/(.*)/ index.php?p=administration&code=$1
RewriteRule ^user/delete/(.*) index.php?p=administration&code=$1
RewriteRule ^user/password/(.*)/ index.php?p=password&code=$1
RewriteRule ^user/password/(.*) index.php?p=password&code=$1

RewriteRule ^user/email/(.*)/ index.php?p=email&code=$1
RewriteRule ^user/email/(.*) index.php?p=email&code=$1
RewriteRule ^user/email/ index.php?p=email&code=$1
RewriteRule ^user/email index.php?p=email&code=$1

RewriteRule ^user/administration ./index.php?p=administration
RewriteRule ^user/characters ./index.php?p=characters

RewriteRule ^user/donate index.php?p=donate

RewriteRule ^user/vote4coins/(.*)/ index.php?p=vote4coins&site=$1
RewriteRule ^user/vote4coins/(.*) index.php?p=vote4coins&site=$1
RewriteRule ^user/vote4coins ./index.php?p=vote4coins

RewriteRule ^admin/log/(.*)/(.*)/ index.php?p=admin&a=log&log=$1&page_no=$2
RewriteRule ^admin/log/(.*)/(.*) index.php?p=admin&a=log&log=$1&page_no=$2

RewriteRule ^admin/log/(.*)/ index.php?p=admin&a=log&log=$1
RewriteRule ^admin/log/(.*) index.php?p=admin&a=log&log=$1

RewriteRule ^admin/functions index.php?p=admin&a=functions
RewriteRule ^admin/createitems index.php?p=admin&a=createitems
RewriteRule ^admin/privileges index.php?p=admin&a=privileges
RewriteRule ^admin/coins index.php?p=admin&a=coins

RewriteRule ^admin/players/(.*)/(.*)/ index.php?p=admin&a=players&page_no=$1&player_name=$2
RewriteRule ^admin/players/(.*)/(.*) index.php?p=admin&a=players&page_no=$1&player_name=$2
RewriteRule ^admin/players/(.*)/ index.php?p=admin&a=players&page_no=$1
RewriteRule ^admin/players/(.*) index.php?p=admin&a=players&page_no=$1
RewriteRule ^admin/players/ index.php?p=admin&a=players
RewriteRule ^admin/players index.php?p=admin&a=players

RewriteRule ^admin/redeem/(.*)/ index.php?p=admin&a=redeem&page_no=$1
RewriteRule ^admin/redeem/(.*) index.php?p=admin&a=redeem&page_no=$1
RewriteRule ^admin/redeem/ index.php?p=admin&a=redeem
RewriteRule ^admin/redeem index.php?p=admin&a=redeem

RewriteRule ^admin/player/edit/(.*)/ index.php?p=admin&a=player_edit&id=$1
RewriteRule ^admin/player/edit/(.*) index.php?p=admin&a=player_edit&id=$1

RewriteRule ^admin/vote4coins/(.*)/ index.php?p=admin&a=vote4coins&del=$1
RewriteRule ^admin/vote4coins/(.*) index.php?p=admin&a=vote4coins&del=$1
RewriteRule ^admin/download/(.*)/ index.php?p=admin&a=download&del=$1
RewriteRule ^admin/download/(.*) index.php?p=admin&a=download&del=$1
RewriteRule ^admin/donate/(.*)/ index.php?p=admin&a=donate&del=$1
RewriteRule ^admin/donate/(.*) index.php?p=admin&a=donate&del=$1
RewriteRule ^admin/(.*)/ index.php?p=admin&a=$1
RewriteRule ^admin/(.*) index.php?p=admin&a=$1
RewriteRule ^admin/ index.php?p=admin
RewriteRule ^admin index.php?p=admin

RewriteRule ^download/ index.php?p=download
RewriteRule ^download index.php?p=download

RewriteRule ^user/referrals/ index.php?p=referrals
RewriteRule ^user/referrals index.php?p=referrals

RewriteRule ^user/redeem/ index.php?p=redeem
RewriteRule ^user/redeem index.php?p=redeem

Instead, I tried to run chialab php apache (with mod_php instead of PHP-FPM), without any change, and the first .htaccess works without any problem. Maybe is there an apache configuration that I am missing?

Thank you for your precious help in advance :)

shinsenter commented 2 months ago

@NazgulCoder Do the URLs of the requests to your website include file extensions? E.g: /abc/xyz.html

NazgulCoder commented 2 months ago

@NazgulCoder Do the URLs of the requests to your website include file extensions?

Hey thanks for the very quick reply

With the other php container (chialab, with mod_php) I can correctly process this URL:

https://test.com/shop/admin - the correct url should be https://test.com/shop/admin.php

With your PHPFPM-Apache when I visit https://test.com/shop/admin it tells me it doesn't find anything at that URL, if I manually force visit https://test.com/shop/admin.php it goes right. However, the rest of the site is already coded and meant to be used with the rewrite conditions above mentioned

shinsenter commented 2 months ago

@NazgulCoder

Thank you for providing the information. I'll double-check the default Apache settings to make sure I haven't added any dumb thing.

NazgulCoder commented 2 months ago

@NazgulCoder

Thank you for providing the information. I'll double-check the default Apache settings to make sure I haven't added any dumb thing.

great thank you very much for your patience :)

For reference if you want to try: https://hub.docker.com/r/chialab/php/ either php-apache 8.0 or 7.4 work fine.

If you want to do some tests on my machine or want the website copy, please let me know

shinsenter commented 2 months ago

@NazgulCoder I have pushed a patch for this issue.

By the way, all Docker images will be re-built after a few hours. Please be patient and try again later.

NazgulCoder commented 2 months ago

@NazgulCoder I have pushed a patch for this issue.

By the way, all Docker images will be re-built after a few hours. Please be patient and try again later.

I'll keep you updated, in 10hours i'll test it again :)

shinsenter commented 2 months ago

@NazgulCoder By the way, to avoid waiting, you might want to try adding a line at the beginning of your .htaccess file and see if that works.

Options -MultiViews
NazgulCoder commented 2 months ago

I tried to pull again your new image but still no luck.

I tried as you said to add to my current .htaccess the

Options -MultiViews

and somehow it did the trick. So in the future if I have other similar issues with url rewrites should I use that rule?

Thanks a lot for your help :)

shinsenter commented 2 months ago

@NazgulCoder Thank you for the feedback.

I tried to pull again your new image but still no luck.

Have you tried checking the creation date of the Docker image to see if it is indeed the latest one? If you’re using Docker Compose, there’s a possibility that Docker might reuse your old container, so you’ll need to delete the old container, and Docker Compose will create a new one from the latest Docker image.

NazgulCoder commented 2 months ago

@NazgulCoder Thank you for the feedback.

I tried to pull again your new image but still no luck.

Have you tried checking the creation date of the Docker image to see if it is indeed the latest one? If you’re using Docker Compose, there’s a possibility that Docker might reuse your old container, so you’ll need to delete the old container, and Docker Compose will create a new one from the latest Docker image.

you were right. I actually recreated the container from portainer but I forgot to tick the re-pull image 😅

I commented Options -MultiViews from my .htaccess and everything works as expected now

Thank you very much for your precious help, hopefully someone else will benefit from this too

shinsenter commented 2 months ago

Thank you again for the feedback.