網站建立了Sitemap.xml文件能夠快速地被Google、Bing等收錄且有利於搜尋的檔案。
CodeIgniter產生的方式:
controller
[php]
Class Seo extends CI_Controller {
function sitemap()
{
$data = "";//網站的url
header("Content-Type: text/xml;charset=iso-8859-1");
$this->load->view("sitemap",$data);
}
}
[/php]
views
[php]
<?= ‘<?xml version="1.0" encoding="UTF-8" ?>’ ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc><?= base_url();?></loc>
<priority>1.0</priority>
</url>
<!– My code is looking quite different, but the principle is similar –>
<?php foreach($data as $url) { ?>
<url>
<loc><?= base_url().$url ?></loc>
<priority>0.5</priority>
</url>
<?php } ?>
</urlset>
[/php]
config/routes.php
$route[‘seo/sitemap\.xml’] = “seo/sitemap”;