How can PHP developers ensure that their website's subpages are properly indexed by search engines like Google?
To ensure that a website's subpages are properly indexed by search engines like Google, PHP developers can create a sitemap.xml file that lists all the subpages of the website. This sitemap file can then be submitted to Google Search Console to help search engines discover and index all the subpages efficiently.
<?php
// Create sitemap.xml file
$pages = array('page1', 'page2', 'page3'); // List of subpages
$xml = new SimpleXMLElement('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>');
foreach ($pages as $page) {
$url = $xml->addChild('url');
$url->addChild('loc', 'https://www.example.com/' . $page); // URL of subpage
}
$xml->asXML('sitemap.xml'); // Save sitemap file
// Submit sitemap.xml to Google Search Console
// Instructions: https://support.google.com/webmasters/answer/183668?hl=en
?>