Docker : URLs except main page cannot be found on server (LAMP)

I dockerized my PHP (Yii 1.1 framework) & MySQL app successfully and First page of my website works fine on http://localhost:8000 but my problem is that when I want to go to another page of my website for example contact page (http://localhost:8000/contact) I face with this error:

Not Found The requested URL was not found on this server. Apache/2.4.54 (Debian) Server at localhost Port 8000

*Note that all of my websites page work fine on real host and even Wamp.

I have .htaccess file like this which works correctly on real host

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./index.php [L]
</IfModule>

And it’s my docker-compose file which I don’t think it has any thing related to this problem because as I said first page of website with all queries work perfectly:

version: '3.8'
services:
    php-apache-environment:
        container_name: php-apache
        build:
            context: ./sweetnfresh
            dockerfile: Dockerfile
        depends_on:
            - db
        volumes:
            - ./sweetnfresh/src:/var/www/html/
        ports:
            - 8000:80
    db:
        container_name: db
        image: mysql
        restart: always
        environment:
            MYSQL_ROOT_PASSWORD: MYSQL_ROOT_PASSWORD
            MYSQL_DATABASE: MYSQL_DATABASE
            MYSQL_USER: user
            MYSQL_PASSWORD: pass
        ports:
            - "9906:3306"
        volumes:
            - ./dbdata:/var/lib/mysql
    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        ports:
            - '8080:80'
        restart: always
        environment:
            PMA_HOST: db
            UPLOAD_LIMIT : 300M
        depends_on:
            - db

Did you try this format? Just three lines. Last line should be a substitution.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

I tried but still it doesn’t work except first page

(You should of course keep the first line(s) in .htaccess)
Do you have a space before index.php in the last line?
I understand this line as “replace any character with index.php”.

What’s in the Apache error log?
I think it’s not probable, but also check the Yii log.

Edit: Try with url “server:port/controller/action”. Problem with url rules?

Yes I complied all your points in .htaccess but it didn’t make any difference
I’ve tried server:port/controller/action and it doesn’t work too.
And it’s log from docker container for http://localhost:8000/contact:
172.18.0.1 - - [15/Jul/2022:06:55:56 +0000] “GET /contact HTTP/1.1” 404 489 “http://localhost:8000/” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36”

I have .htaccess files starting with this line

Options +FollowSymLinks

I don’t know exactly why it’s there. Perhaps it’s required and was missing in the Apache config.

No it doesn’t work too. I think it must be related to apache docker image config because I’ve tried all standard types of .htaccess
Thank you for your suggestions!