@Simon Lovejoy , Apologies for the delayed response from over the weekend.
Azure App Service on Linux images using PHP 8.x are now bundled with NGINX instead of Apache. The use of htaccess
files will not work for NGINX as these are used for Apache only. This will require the need to setup a custom startup script and modifying the existing NGINX site configuration.
Just to clarify, is this a built-in/blessed image or a custom docker image? What is the application framework?
Navigate to App Service Web SSH via https://<YourWebAppName>.scm.azurewebsites.net/webssh/host
- You will want to make a copy of the existing configuration and place the file inside the
/home/site
directory. - You will now need to create a custom startup script and save the file as
/home/site/startup.sh
- Reloading the NGINX service to make the updates take effect.
See this article for step-step instructions: Configure Nginx for PHP 8 Linux Azure App Service
Depending on the framework you are using, on App service in general, (as an example ) Node App Service on Linux that the environment is a Docker Container which includes Node itself (along with your code) and also PM2, a production process manager - called our “Blessed Images”.
If using something like Expressjs and have your controllers set up for routing, the below approach can be used, which is using an exported function that we can pass back into our routing middleware. req, res, next
will be available since this function can be passed as an argument directly to Express middleware. This example is redirecting from non-www to www:
const redirectController = (req, res, next) => {
try {
const host = req.headers.host;
if (host.match(/^www\..*/i)) {
next();
} else {
res.redirect(301, `${req.protocol}://www.` + host + req.url);
}
} catch (error) {
console.log("An error has occurred: ", error);
next(error);
}
};
module.exports = redirectController;
Refer to NGINX Rewrite Rules for Azure App Service Linux PHP 8.x for details.
Kindly let us know, I'll follow-up with you further.