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

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

Profile Picture of Bryan Myers - The Web Guy

Bryan Myers - "The Web Guy"

Advanced Digital Channel Engineer

Tags

  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