简体   繁体   中英

How can I configure the htaccess file in silverstripe on docker?

I have a project based on the SilverStripe framework and I want to move it on docker, but after the docker configuration, it has some problem with loading the project from public folder. It works fine without docker on my local wamp but after moving on docker, it's not able to recognize my friendly URL. eg http://localhost:8080/admin

Dockerfile :

FROM php:7.3-apache
ENV DOCUMENT_ROOT /var/www/html/public
    
COPY . $DOCUMENT_ROOT
WORKDIR $DOCUMENT_ROOT

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
COPY composer.json composer.json
COPY composer.lock composer.lock
#RUN composer install --no-dev
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf &&\
    a2enmod rewrite &&\
    service apache2 restart
RUN apt-get update && apt-get install -y apt-transport-https
RUN apt-get install -y libicu-dev
RUN docker-php-ext-configure intl && docker-php-ext-install intl
RUN docker-php-ext-install mysqli pdo pdo_mysql

docker-compose.yml :

version: '3.8'
services:
  web:
    image: backend
    working_dir: /var/www/html
    volumes:
      - .:/var/www/html
    ports:
      - 8080:80
  database:
    image: mysql:5.7
    volumes:
      - db-data:/var/lib/mysql
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=true
  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    environment:
      PMA_HOST: database
      PMA_USER: root
      PMA_PASSWORD:
      UPLOAD_LIMIT: 1280M
      MEMORY_LIMIT: 1280M
      MAX_EXECUTION_TIME: 600
    ports:
      - 8089:80
volumes:
  db-data:

.htaccess file:

RewriteEngine On 
RewriteRule ^(.*)$ public/$1

After investigation, I've found the below .htaccess file to fix the problem:

RewriteEngine On
Options Indexes SymLinksIfOwnerMatch FollowSymLinks
DirectoryIndex index.php index.html /example.php
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
RewriteRule (.+) public/$1 [L]
RewriteRule (.*) public/index.php?path=$1 [L,QSA]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM