thalhah Posted September 21, 2017 Share Posted September 21, 2017 Hi, I create my own sitemap.xml for WHMCS Knowledgebase. here's the code. <?php // ####################### SET WHMCS ENVIRONMENT ######################## use WHMCS\ClientArea; define('CLIENTAREA', true); require_once("init.php"); require_once("includes/functions.php"); require_once("includes/clientareafunctions.php"); // ######################### CONNECT TO DATABASE ######################## $db = mysqli_connect($db_host, $db_username, $db_password, $db_name); if (mysqli_connect_errno()) { echo "Failed to connect to Database: " . mysqli_connect_error(); } $sql_whmcs = mysqli_query($db,"SELECT * FROM tblconfiguration WHERE setting='SystemURL' LIMIT 1"); $rlt_whmcs = mysqli_fetch_array($sql_whmcs); $CFG["siteurl"] = substr($rlt_whmcs["value"], 0, -1); header('Content-Type: application/xml; charset=utf-8'); echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n"; $result = mysqli_query($db,"SELECT * FROM tblknowledgebase"); while ($data = mysqli_fetch_array($result)) { $title = str_replace(array(' ','/'), '-', $data['title']); $title = str_replace(array('?','.','[',']','"'), '', $title); echo '<url>'."\n"; echo '<loc>'.$CFG["siteurl"].'/knowledgebase/'.$data['id'].'/'.$title.'.html'.'</loc>'."\n"; echo '</url>'."\n"; }//while echo '</urlset>'."\n"; ?> 0 Quote Link to comment Share on other sites More sharing options...
yasweb Posted May 26, 2019 Share Posted May 26, 2019 upload root ? page url ? 0 Quote Link to comment Share on other sites More sharing options...
21st Webb Posted February 3, 2020 Share Posted February 3, 2020 Have managed to get the code submitted by thalhah to work with some minor modifications: <?php header('Content-type: application/xml; charset=utf-8') ?> <?php echo '<?xml version="1.0" encoding="UTF-8"?>' ?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <?php // ####################### SET WHMCS ENVIRONMENT ######################## use WHMCS\ClientArea; define('CLIENTAREA', true); require_once("init.php"); require_once("includes/functions.php"); require_once("includes/clientareafunctions.php"); // ######################### CONNECT TO DATABASE ######################## $db = mysqli_connect($db_host, $db_username, $db_password, $db_name); if (mysqli_connect_errno()) { echo "Failed to connect to Database: " . mysqli_connect_error(); } $sql_whmcs = mysqli_query($db,"SELECT * FROM tblconfiguration WHERE setting='SystemURL' LIMIT 1"); $rlt_whmcs = mysqli_fetch_array($sql_whmcs); $CFG["siteurl"] = substr($rlt_whmcs["value"], 0, -1); $result = mysqli_query($db,"SELECT * FROM tblknowledgebase"); while ($data = mysqli_fetch_array($result)) { $title = str_replace(array(' ','/'), '-', $data['title']); $title = str_replace(array('?','.','[',']','"'), '', $title); echo ' <url>'."\n"; echo ' <loc>'.$CFG["siteurl"].'/knowledgebase/'.$data['id'].'/'.$title.'.html'.'</loc>'."\n"; echo ' </url>'."<br>"; }//while echo '</urlset>'."\n"; ?> Save this as sitemap.php in your WHMCS root folder within your public_html directory, i.e. public_html/whmcs/sitemap.php This will now correctly output each Knowledgebase article's URL on a separate line within XML format. You can now add the URL of your sitemap.php file to Google and Bing Webmasters as it is, no need to use a .htaccess rewrite rule to convert sitemap.xml to sitemap.php unless you really want to. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.