1. Home
  2. Articles
  3. Web Development
  4. PHP
  5. Dynamic XML Sitemap Using PHP and .htaccess Rewrite

Dynamic XML Sitemap Using PHP and .htaccess Rewrite

Published:

Share

Description

It's been awhile since I have worked with htaccess files on a Apache web server. If I recall correctly, I should be able to use the rewrite mod to handle dynamic URIs. Another item to look at is the creation of a dynamic XML sitemap. To the code!

Article

As things are moving over to indexable content, I figured it was time to produce a sitemap for Google and Bing to gobble up through Google Webmaster Tools and Bing Webmaster Tools. I need a solution that would be dynamic and produce a valid XML file on demand. The following .htaccess, PHP and XML code laid the foundation. The rest was handled with some mySQL querys and PHP output.

.htaccess

RewriteRule ^sitemap\.xml$ sitemap.php [L]

PHP

header('Content-type: application/xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?>';

XML

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<url>
		 <loc>https://www.bryan-myers.com/</loc>
		 <changefreq>daily</changefreq>
		 <priority>1</priority>
	</url>
</urlset>

Not saying I am going to submit anytime soon. But I am not going to complain if a search engine spider crawls the site through organic means.

SOON! Mahahah! SOON! /grin

Author

Tags

  1. Articles
  2. Web Development
  3. PHP

Related Articles