Azure App Service WordPress URL Rewrite

Frank van Graafeiland 166 Reputation points
2021-10-17T10:43:42.247+00:00

Hello,

I could use some help with an Azure Web App which runs a WordPress website.
The problem I am facing is that the permalink structure in WordPress cannot be altered without running into 404 errors. The current permalink structure is:
domainname/index.php/pagename

I would really like to get rid of the index.php, but all the attemps I have made have failed.
I'm used to working with WordPress on Apache, which uses .htaccess to rewrite the URLs. But Azure App Server PHP doesn't run on Apache, so this is not an option.

So far I have tried the following (to no avail):

  1. Created a web.config file in site/wwwroot according to the instructions in the link below with the value of the "Proper web.config" comment, and restarted the Web App.
    https://stackoverflow.com/questions/38030555/url-rewrite-azure-php
  2. Installed and activated a WordPress plugin which handles permalinks and restarted the Web App.

The root directory is called wwwroot, which suggest the site is running on IIS, but when I get a 404 error it says nginx/1.14.2 below. This confuses me a little because I believe the "web.config" solution is meant for IIS and I've read that if you want to change the permalinks when running WordPress on NGINX, some NGINX configuration changes need to be made. I wouldn't know where I could configure NGINX in Azure App Service, if at all possible.

Any help will be greatly appreciated!

Kind regards,

Frank

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,895 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Ryan Hill 25,741 Reputation points Microsoft Employee
    2021-10-18T16:30:22.277+00:00

    To start, there are currently two WordPress templates in the marketplace; one for Windows and other for Linux. You can confirm which one you have by going to your {your-wordpress-site}.scm.azurewebsites.net/api/processes.

    Your app root directory will be the same for both hosting environments (e.g. /home/site/wwwroot), but if your WordPress site is being hosted on Linux, it's using the new PHP 8 blessed image, which uses nginx as webserver in place of Apache. In that instance, web.config doesn't apply. However, this blog post is a good place to start in how make rewrite rules for nginx using the .htaccess file.

    1 person found this answer helpful.
    0 comments No comments

  2. Frank van Graafeiland 166 Reputation points
    2021-10-21T18:27:38.95+00:00

    Hi Ryan,

    Thanks for the answer. I'm not actually using a marketplace image, but instead I downloaded and installed the latest version of WordPress from wordpress.com itself. I tried using a WordPress template from the marketplace once, but found that the entire SSH section was sealed off by the creator of the template. I never bothered with it again.

    "{your-wordpress-site}.scm.azurewebsites.net/api/processes" responds with: "Not supported on Linux"

    The Web app runs on Linux PHP 8.0.

    I've read the blog post you sent and I changed the default content of the .htaccess file (which I thought was missing, but obviously isn't) to:
    location / {
    try_files $uri $uri/ /index.php?$args;
    }

    The permalinks now still can't be changed without receiving 404 errors.
    I assume that's because NGINX doesn't look at a .htaccess file for its rewrite rules. Unfortunately, nowhere in that blog post, or the other blog post that is referred to at the start, "Creating NGINX Rewrite Rules" https://www.nginx.com/blog/creating-nginx-rewrite-rules/", can I find where to place the file that NGINX bases its rewrite rules off, or what name that file should be given.

    Would you happen to know if it's as simple as creating a file with a specific name in a specific directory with the following content:
    location / {
    try_files $uri $uri/ /index.php?$args;
    }
    And if you do, what the location and name of the file should be?
    If not: thanks a lot anyway!

    Kind regards,

    Frank

    1 person found this answer helpful.

  3. Gabor Illes2 6 Reputation points
    2021-11-23T10:36:10.73+00:00

    Hi Frank,,

    Were you able to resolve your problem?
    If so, could you post your solution - I'm dealing with the same.

    Thanks and regards,
    Gabor

    1 person found this answer helpful.
    0 comments No comments