You are here
Home > Php > Create Dynamic XML Sitemap Using PHP

Create Dynamic XML Sitemap Using PHP

If you are managing a website that has large numbers of pages, it’s very difficult to add all URLs in sitemap one by one Especially if page creation frequency is high. Either you are an SEO or Developer, I am sure you had to face this problem. So today I am here with the solution. It’s very easy but a little tricky.

The sitemap is used to submit all internal URLs to Search Engines like Google, Yahoo, Bing, etc for indexing.

So, Without wasting time let’s learn how to create¬† Dynamic XML Sitemap using PHP

Go to the website root folder or anywhere you want to put a sitemap file. For learning, i am using root path public_html & create a file named sitemap.php & add the source code.

Source Code


Wait… It’s not completed yet. Probably you forgot to check the URL. It’s with .php extension. But Google support only .xml sitemap

To solve this problem you need to add this code to the .htaccess file. Its rewrite .php extension to .xml for sitemap.php.

If you have any question, Kindly reply in comment section. Please like & share if you want more similar posts

Vivek Pal
I am a Web Developer with strong specifications in CMS as Wordpress Magento etc. Having good Knowledge of HTML, CSS, Bootstrap Photoshop Cloud Solution (G Suite, O365, GCP, Amazon AWS), Domains, Hosting, etc. I also have a good knowledge of Internet marketing. (SEO, SMO, PPC), I have more than 5 years of experience. I consistently deliver creative scalable solutions that reflect the personality needs the vision of my clients