Welcome Guest, Not a member yet? Register   Sign In
Problem sitemap.xml
#1

(This post was last modified: 11-03-2015, 10:31 AM by patguitar.)

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
Reply
#2

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.
Reply
#3

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 ?
Reply
#4

(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'); 
Reply
#5

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

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
Reply
#7

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB