Score:0

Rewriting dynamic urls in nginx config

do flag

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");
}
?>
us flag
What is the output of `curl -v` when you try to load a sitemap? What is the exact request URL?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.