Setting up 301 redirects for an Azure Web App

Jimmy Hat 21 Reputation points

Our 301 redirects stopped working roughly halfway through 2021 apparently as a result of ms updating or changing the underlying infrastructure or something related thereto to 'nginx'.

I do not have further specific technical detail around - nor are we overly concerned about this aspect of the challenge - as we had to work with engineering to figure out what had happened. The above was feedback from their end.

Our people have set up (or edited) the file titled 'default', which appears to exist in the /site directory of the azure web app. the structure of this file is laid out as follows.

server {  
    #proxy_cache cache;  
	#proxy_cache_valid 200 1s;  
    listen 8080;  
    listen [::]:8080;  
    root /home/site/wwwroot;  
    index  index.php index.html index.htm;  
    server_name our-server-address-here;  
    port_in_redirect off;  
location = /our-old-url-goes-here.htm {  
return 301 $scheme://;  
location = /our-old-url-goes-here.htm {  
return 301 $scheme://;  
location = /our-old-url-goes-here.htm {  
return 301 $scheme://;  
    location / {              
        index  index.php index.html index.htm hostingstart.html;  
    # redirect server error pages to the static page /50x.html  
    error_page   500 502 503 504  /50x.html;  
    location = /50x.html {  
        root   /html/;  
    # Disable .git directory  
    location ~ /\.git {  
        deny all;  
        access_log off;  
        log_not_found off;  
    # Add locations of phpmyadmin here.  
    location ~ [^/]\.php(/|$) {  
        fastcgi_split_path_info ^(.+?\.php)(|/.*)$;  
        include fastcgi_params;  
        fastcgi_param HTTP_PROXY "";  
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  
        fastcgi_param PATH_INFO $fastcgi_path_info;  
        fastcgi_param QUERY_STRING $query_string;  
        fastcgi_intercept_errors on;  
        fastcgi_connect_timeout         300;   
        fastcgi_send_timeout           3600;   
        fastcgi_read_timeout           3600;  
        fastcgi_buffer_size 128k;  
        fastcgi_buffers 4 256k;  
        fastcgi_busy_buffers_size 256k;  
        fastcgi_temp_file_write_size 256k;  

Currently, this does not appear to work. Redirects that are added after the location elements above are not redirecting succesfully and I can not seem to find any documentation around this functionality or feature.

Is there something that has to be set perhaps from within the web app's interface in order to utilise this 'default' file? Or otherwise any documentation from ms providing detail on how to implement 301s correctly within one of these azure web apps?

To caveat all of the above, i should note that I only enjoy a limited understanding of the azure platform. As such, I am reaching out to this community in the hopes that someone else may read this having experienced the same challenge prior to me.

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

1 answer

Sort by: Most helpful
  1. VenkateshDodda-MSFT 9,376 Reputation points Microsoft Employee

    @Jimmy Hat Thanks you for reaching out to Microsoft Q&A. Apologize for the inconvenience caused on this.

    Based on the shared information we have understood that you are web app is running on PHP 8.x.

    To test this behavior, I have created a webapp which is running with php8.0 and added the below redirect rule all the incoming requests to /hostingstart.html will get redirected to /test.php which is present under the path /home/site/wwwroot.


    Since you are changing the default configuration you need to create a custom startup script to make these changes applicable. follow the below set of instructions to create Nginx redirect rule and custom startup script to your web app.

    • Navigate to your App Service via the Azure Portal. Under the Development Tools section, select SSH then Go -->.
    • Copy the existing configuration and place the file inside the /home/site directory using this cmdlet cp /etc/nginx/sites-available/default /home/site/default
    • Once you copy default file to /home/site/default edit the default file with your required changes.
    • Create a custom startup script with the below and save the file as /home/site/


    • Go to General Settings section under Configuration blade of you web app, For the Startup command enter the path /home/site/
    • Save these settings and restart your Web App.

    Reference documentation for writing Nginx Redirect rules for php8.x App service.
    Feel free to reach back to me if you have any further questions on this.