I'm working on a PHP app, and I have moved it from apache to nginx server. I have a php page that dynamically creating xml files for sitemap . This works perfectly in apache server but when i moved to nginx its not working .
This is the code that i'm using in apache
RewriteRule ^([^/]+)\.xml/?$ sitemap.php?p=$1 [QSA,L]
This is the code i used in nginx
rewrite "^/([^/]+)\.xml/?$" /sitemap.php?p=$1 last;
This is the complete nginx config file.
This is what i'm using to create the xml pages dynamically (complete code not included)
<?php
require_once( './inc/header.inc.php' );
$connect = mysqli_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASS, DATABASE_NAME);
mysqli_set_charset($connect, "utf8");
header("Content-Type: application/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
// How many items to list per page
$limit = 10000;
if (!empty($_GET["p"])) {
$page = $_GET["p"];
if ($page === "sitemap_core") {
// Sitemap Core Page Starts
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'.PHP_EOL;
$core_sitemap_url_arr = array('terms', 'join', 'login', 'blog/', 'about-us', 'sb', 'sm', 'msb');
foreach ($core_sitemap_url_arr as $url) {
echo '<url>'.PHP_EOL;
echo '<loc>'.BX_DOL_URL_ROOT.$url.'</loc>'.PHP_EOL;
echo '<lastmod>'.date('Y-m-d').'</lastmod>'.PHP_EOL;
echo '<changefreq>daily</changefreq>'.PHP_EOL;
echo '</url>'.PHP_EOL;
}
echo '</urlset>'.PHP_EOL;
// Sitemap Core Page Ends
}
}
else {
header("Location:" .BX_DOL_URL_ROOT."404");
}
?>