I have this Single Page Application built using AngularJS that resides in the document root.
The SPA communicates with an API built using CakePHP 3.5.x. The CakePHP instance resides in a folder named /api. All requests from the SPA are sent to www.example.com/api/some-action.json. This is working out fine and no issues here.
However, I also have a administration backend built in the CakePHP and accessible via a CakePHP routing prefix of “admin”.
If the Cake app were to reside in top-level documentroot, I could have easily accessed this via www.example.com/admin. Since the Cake app is in the api subfolder, I’m attempting to access it via www.example.com/api/admin and getting a 404 from IIS (default 404 page of IIS).
If I simply access www.example.com/api - I drop to the default CakePHP start page that you see after a fresh installation… so no issues with the installation itself.
And this URL structure works just fine on my local xampp instance with Apache.
Here are my IIS Rewrite rules:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<customErrors mode="Off" />
</system.web>
<system.webServer>
<rewrite>
<rules>
<rule name="Exclude direct access to webroot/*" stopProcessing="true">
<match url="^webroot/(.*)$" ignoreCase="false" />
<action type="None" />
</rule>
<rule name="Rewrite routed access to assets(img, css, files, js, favicon)" stopProcessing="true">
<match url="^(img|css|cache_css|font|files|js|audio|cache_js|favicon.ico|favicon-*.png|Favicon*.png|AndroidIcon*.png|manifest.json)(.*)$" />
<action type="Rewrite" url="webroot/{R:1}{R:2}" appendQueryString="false" />
</rule>
<rule name="Rewrite requested file/folder to index.php" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Stack:
- Windows Server 2016
- IIS 10
- PHP 7.1
- AngularJS 1.6
- CakePHP 3.5.x
- Percona XtraDB (MySQL)
What tweaks in the rewrite rules do I need to carry out to get the CakePHP routing prefix(es) and any url parts that follow to render properly? The rule should take care of www.example.com/api/admin/*.
Sincere thanks.