Business Claud
Business Claud

Reputation: 21

CodeIgniter Sitemap problem view not in xml format

Something is not right. CodeIgniter... the output is not in xml format. Just found out an hour ago that i can see the sitemap php page businessclaud.co.ke/sitemap but its not in xml format... take a look and please help

I have this controller named Sitemap.php

<?php
class Sitemap extends Controller {
    public function __construct(){
    require APPROOT.'/views/inc/load_models.php';
}

public function index(){
    $this->view('sitemap/index');
}

}

Also created the view index.php and uploaded to the site shown below

<?xml version="1.0" encoding="UTF-8"?>
<urlset
      xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<!-- created with Free Online Sitemap Generator www.xml-sitemaps.com -->


<url>
  <loc>https://businessclaud.co.ke/</loc>
  <lastmod>2021-06-19T02:02:46+00:00</lastmod>
  <changefreq>daily</changefreq>
  <priority>1.00</priority>
</url>
<url>
  <loc>https://businessclaud.co.ke/admin/users/login</loc>
  <lastmod>2021-06-19T02:02:46+00:00</lastmod>
  <changefreq>daily</changefreq>
  <priority>0.80</priority>
</url>

enter link description here

Something is not right. Just found out an hour ago that i can see the php xml page businessclaud.co.ke/sitemap but its not in xml format... take a look and please help

Upvotes: 0

Views: 541

Answers (1)

Business Claud
Business Claud

Reputation: 21

I found out that since the sitemap view is in php format that is index.php what you need to do is tell the browser to treat it as xml. This is done by defining the header header("Content-type: text/xml");.

If you are facing a problem like this, go to your controller and add this line header("Content-type: text/xml");.

<?php
class Sitemap extends Controller {
    public function __construct(){
//  require APPROOT.'/views/inc/load_models.php';
}

public function index(){
    header("Content-type: text/xml");
    $this->view('sitemap/index');
}

}

And just like that, the site is ready to submit a sitemap.

Upvotes: 1

Related Questions