Here for the SEO implementation we need to generate the sitemap.xml in our application which is accessed by the webmaster tool. So here i am outlined the steps to generate the Xml file .
1. Lets think we have controller by name sitemap,Inside that create an action by name sitemap and paste the following code
public function sitemap(){$this->layout='ajax'; $this->RequestHandler->respondAs('xml'); $listData = $this->Sitemap->find('all',/*Conditions if you have any*/); $this->set(compact('listData')); }
I through variable $listData to render all data( Keywords,Title,Url,etc ...) that will be shown in sitemap.xml. This depends on the dynamic link what we want to show in sitemap.xml.For request handler to work include the RequestHandler component
public $components = array('RequestHandler');
Step 2. Create View based on action sitemap
On structure MVC as default we need create sitemap.ctp. On this file we will show content of sitemap.xml. This bellow are code for sitemap.ctp.Here i am fetching the data from the list table. You can change the table based on your requirement .
<?php App::uses('CakeTime', 'Utility'); ?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc><?php echo $this->Html->url('/',true); ?></loc> <changefreq>weekly</changefreq> </url> <?php foreach ($listData as $list): ?> <url> <loc><?php echo $this->Html->url(array('controller' => 'list', 'action' => 'detail',$list['List']['id']),true); ?></loc> <lastmod><?php echo $this->Time->toAtom($list['List']['modified']); ?></lastmod> <changefreq>weekly</changefreq> </url> <?php endforeach; ?> </urlset>
Step 3. Set config routes.php
This is last step for configure path our sitemap will be appear like www.yourdomain.com/sitemap.xml. Add this bellow code after line connect / (if there)
This is last step for configure path our sitemap will be appear like www.yourdomain.com/sitemap.xml. Add this bellow code after line connect / (if there)
Router::parseExtensions('*.xml');
Router::connect('/sitemap.xml', array('controller' => 'Sitemaps', 'action' => 'sitemap'));
Thats all we need to do , Now try accessing the url www.yourdomain.com/sitemap.xml, It should display the Xml format. If you are getting the result in the Xml format , you can proceed in submitting the Url to the webmaster tool.
Thank you.Well it was nice post and very helpful information on Ruby on Rails Online Course
ReplyDelete