Search code examples
phpazureazure-web-app-servicereroute

How to use PHP routing script in azure?


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.


Solution

  • 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