<p>I'm moving my app from Azure App Service to Azure Kubernetes Service and I need to dockerize it. It's a simple typescript/react app. I'd typically build and run it with the following sequence:</p>
<pre><code>yarn
yarn staging
serve -s build -l 5000
</code></pre>
<p>However there is a little twist. I have a couple <code>php</code> pages that I need to support. How do I route all the traffic to <code>/index.html</code> except for the requests that land on <code>*.php</code> - those need to be processed as php scripts. Azure App Service would allow me to run my HTML5 app with PHP side by side. How do I achieve it with docker? What should my Dockerfile look like?</p>
<p>Here is what I came up with for now:</p>
<pre><code># Step 1
FROM node:10-alpine as build-step
RUN mkdir /app
WORKDIR /app
COPY . /app

RUN yarn
RUN yarn staging

# Stage 2
FROM php:7.2-apache
COPY --from=build-step /app/build /var/www/html
EXPOSE 80
CMD [&quot;/usr/sbin/apache2ctl&quot;, &quot;-D&quot;, &quot;FOREGROUND&quot;]
</code></pre>
<p>But this doesn't redirect to /index.html if I open <a href="http://example.com/non-existing-page" rel="nofollow noreferrer">http://example.com/non-existing-page</a>.</p>

Andrei
<p>After all the research I've managed to achieve the desired behaviour which is:</p>
<ul>
<li>Build react app with yarn</li>
<li>Single Page Application URL rewriting</li>
<li>Enabled PHP. I can open http://*.php webpagees</li>
<li>Open /webpage and if there is webpage.php it would open php.</li>
</ul>
<p>My final Dockerfile:</p>
<pre><code># Build
FROM node:10-alpine as build

ARG envType=staging

RUN echo ${envType}

RUN mkdir /app

WORKDIR /app

COPY . /app

RUN yarn

RUN yarn ${envType}

# Run
FROM php:7.3-apache

COPY --from=build /app/build /var/www/html

RUN a2enmod rewrite

EXPOSE 80
</code></pre>
<p>And .htaccess file with rewrite rules:</p>
<pre><code>&lt;ifModule mod_rewrite.c&gt;
    RewriteEngine On

    # check to see if the request is for a PHP file:
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^/?(.*)$ /$1.php [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !index
    RewriteRule (.*) index.html [L]
&lt;/ifModule&gt;
</code></pre>
