CodeIgniter Forums
Problem sitemap.xml - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Problem sitemap.xml (/showthread.php?tid=63472)



Problem sitemap.xml - patguitar - 11-03-2015

Hello,

For my new website, I want to add a sitemap.xml , I can't.

Normally it is very simple, I have only 4 pages, so I do not need to automatically generate the sitemap.

I use HMVC

My controler

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

Class Seo extends MX_Controller {

function index(){
redirect(base_url(),'refresh');
}

   function sitemap()
   {
      header('Content-Type: text/xml');
      $this->load->view('sitemap'); // My xml file - sitemap.xml
   }
}

The file sitemap.xml

Code:
<?xml version="1.0" encoding="UTF-8" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
 <loc>http://www.mysite.com/</loc>
 <changefreq>weekly</changefreq>
 <priority>1.00</priority>
</url>
<url>
 <loc>http://www.mysite.com/page1</loc>
 <changefreq>weekly</changefreq>
 <priority>0.80</priority>
</url>
<url>
 <loc>http://www.mysite.com/page2</loc>
 <changefreq>weekly</changefreq>
 <priority>0.80</priority>
</url>
<url>
 <loc>http://www.mysite.com/page3</loc>
 <changefreq>weekly</changefreq>
 <priority>0.80</priority>
</url>
<url>
 <loc>http://www.mysite.com/page4</loc>
 <changefreq>weekly</changefreq>
 <priority>0.80</priority>
</url>
</urlset>

When I lauch the url, http://www.mysite.com/seo/sitemap, I get this error

Code:
Erreur d'analyse XML : balise ne correspondant pas. Attendu : </meta>.
Emplacement : http://localhost/kojite/seo/sitemap
Numéro de ligne 56, Colonne 3 :</head>
--^

I try to configure the route as I have seen on some forums

Code:
$route['seo/sitemap\.xml'] = "seo/sitemap";

But, with or without the route configured, it's the same result

Thank's for your help

Patrice


RE: Problem sitemap.xml - AidanW - 11-03-2015

If it doesn't need to be generated dynamically you could just put sitemap.xml file in the root directory, no need to route to it.


RE: Problem sitemap.xml - patguitar - 11-03-2015

Hello,

Ok I'am to bad, effectively, it works like that, thank you very match.

Actually, it works if I put the file in the root directory of my app

But if I want to store it in the view folder, do you know if is it possible ?


RE: Problem sitemap.xml - pdthinh - 11-03-2015

(11-03-2015, 11:13 AM)patguitar Wrote: Hello,

Ok I'am to bad, effectively, it works like that, thank you very match.

Actually, it works if I put the file in the root directory of my app

But if I want to store it in the view folder, do you know if is it possible ?

You can put xml file in the view folder. Your sitemap() function is correct except to load view file in other format than php, you must specify it

PHP Code:
$this->load->view('sitemap.xml'); 



RE: Problem sitemap.xml - freddy - 11-03-2015

Emplacement : http://localhost/kojite/seo/sitemap <--it errors came from local or already server ?


RE: Problem sitemap.xml - patguitar - 11-04-2015

Hello pdthinh,

Your answer is good and works, for that, I need to set the route :

Code:
$route['seo/sitemap\.xml'] = "seo/sitemap";

for freddy,

If I just use

Code:
$this->load->view('sitemap');

With or without route, error 404

thank's for your help

Patrice


RE: Problem sitemap.xml - patguitar - 11-04-2015

Hello pdthinh,

Your answer is good and works, for that, I need to set the route :

Code:
$route['seo/sitemap\.xml'] = "seo/sitemap";

for freddy,

If I just use the code from local or server

Code:
$this->load->view('sitemap');

With or without route, error 404

thank's for your help

Patrice