How to use PHP routing script in azure?

364 Views Asked by At

I am currently running a inbuilt server and i want to transfer it to azure. At the moment I run the server with the following command

php -S localhost:8000 route.php

where route.php is my routing script which deals with all my requests. I have looked though the application setting in azure and I cant seem to find the required setting.

2

There are 2 best solutions below

0
AlexanderRD On BEST ANSWER

Web.config can be used to modify to the request before it is processed by the server. Therefore the following script can be used to push the traffic to the routing script

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
<system.webServer>
<rewrite>
    <rules>
        <rule name="SpecificRewrite" stopProcessing="true">
            <match url="^([A-Za-z0-9-/]+)/?$" />
            <action type="Rewrite" url="/route.php?url={R:1}" />
        </rule>
        </rules>
    </rewrite>
</system.webServer>
</configuration>

The match and action parameters each regular expressions so can be modified for advanced routing

1
Gary Liu On

PHP applications running on Azure Web Apps are hosted on IIS, and if I haven't misunderstood, you are using route.php as the entrance of your application.

You can configure the Default documents under Application settings blade on Azure portal, enter image description here set the route.php at the first place, then, when the request comes in, the IIS will find the pages one by one under the dufault document list, to handle the request.