- Server operating system version
- Ubuntu 24.04.1
- Plesk version and microupdate number
- 18.0.64
Hi All,
Through Plesk, I am trying to modify my nginx additional directives so that "/sitemap.php" redirects to "/sitemap.xml". When going to "/sitemap.xml" it should serve the page with "/sitemap.php". I have written the location blocks below:
location ~ ^/sitemap.xml {
try_files $uri /sitemap.php;
}
location ~ ^/sitemap.php {
return 301 /sitemap.xml;
}
This causes a redirect loop back and forward between /sitemap.xml and /sitemap.php. I researched to find some methods to prevent this, such as adding last after the try_files statement or adding a check to not redirect with a 301 if the user is already at the sitemap.php page. These would work on other systems, however seem to be overriding some of the config plesk has already written, causing my PHP page to get downloaded instead of displayed.
Does anyone know how I can fix this problem when writing my nginx.conf in a plesk environment? Help would be much appreciated.
Through Plesk, I am trying to modify my nginx additional directives so that "/sitemap.php" redirects to "/sitemap.xml". When going to "/sitemap.xml" it should serve the page with "/sitemap.php". I have written the location blocks below:
location ~ ^/sitemap.xml {
try_files $uri /sitemap.php;
}
location ~ ^/sitemap.php {
return 301 /sitemap.xml;
}
This causes a redirect loop back and forward between /sitemap.xml and /sitemap.php. I researched to find some methods to prevent this, such as adding last after the try_files statement or adding a check to not redirect with a 301 if the user is already at the sitemap.php page. These would work on other systems, however seem to be overriding some of the config plesk has already written, causing my PHP page to get downloaded instead of displayed.
Does anyone know how I can fix this problem when writing my nginx.conf in a plesk environment? Help would be much appreciated.