1. Home
  2. Articles
  3. Web Development
  4. PHP
  5. Dynamic XML Sitemap Using PHP and .htaccess Rewrite
Read about php dynamic xml sitemap using htaccess url rewrite mod

Dynamic XML Sitemap Using PHP and .htaccess Rewrite




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!


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.


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


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


<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

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


Profile Picture of Bryan Myers - The Web Guy

Bryan Myers - "The Web Guy"

Advanced Digital Channel Engineer


  1. Articles discussing web related topics and technologies.Articles
  2. Articles on the Web Development topics.Web Development
  3. Articles covering PHP web development.PHP

Related Articles

Go Back