0

Hi,

I have a sitemap and have decided to create an automated sitemap.

I just wanted to ask would the way i am going to do it be ok.

I was going to create a table let say called `sitemap` have a column in the table called `url`. Basically i would create a section in my admin so i can manually add/delete/edit if i wanted to.

then i was going to create a sitemap.xml file

in that file i was going to create a simple php script that querys the database and using mysql_fetch_array to get everything from the url column and echo it out something like the below, i just created the below script quickly as an example:

<?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">

<?php
        // my global file will go here
	sql_con(); // function to connect to db in global file
	$query = mysql_query("SELECT * FROM `sitemap`");
	$fetch_data = mysql_fetch_array($query);

echo "<url>";
echo "<loc>" . $fetch_data['url'] . "</loc>";
echo "<changefreq>always</changefreq>";
echo "</url>";

?>
</urlset>

Would something like this work?

If it does i will be adjusting some of my scripts that i have to insert url whilst for example submitting a blog post so i wont have to manually add to db, but before i go anyfurther i wanted to maker sure would something like the above work.

Thanks
Genieuk

Edited by genieuk: n/a

4
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by almostbob
0

Just realised sitemap file will be an xml file, forgot about that stupid me.

Anyone know which is best to do what i want?

I looked online for some tutorials to see how others do it but could not find anything.

Thanks,
Genieuk

Edited by genieuk: n/a

0

Just realised sitemap file will be an xml file, forgot about that stupid me.

Anyone know which is best to do what i want?

I looked online for some tutorials to see how others do it but could not find anything.

Thanks,
Genieuk

I like this one ,and another

0

The first part of it is pretty much okay although as you stated the PHP won't be parsed in the XML file so my think leads me to have a CRON Job to run a seperate PHP file that will render the XML code then overwrite the code that is already inside the XML document say you could do this every hour or so.

0

apache mod_rewrite in the .htaccess file
any calls for sitemap.xml ,,,

RewriteEngine ON
RewriteRule ^sitemap.xml? sitemap.php

so just make your php script a php script

Edited by almostbob: n/a

0

Thanks for your replies, sorry so late posting back. Do you mean the script above would be fine then as long as i use that rewrite rule in .htacces?

Thanks
GUK

0

rewrite rule should redirect any call to sitemap.xml to sitemap.php if mod_rewrite is compiled in to the apache server, by default it is, but...
just change the second filename to ''whatever your script is''.php

Your xml script with php in it, will have to be a .php file for the parser to run on it, use php headers to set the output to the expected text/xml

there would have to be a foreach somewhere in your array processing to get each element, I think

Edited by almostbob: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.