Question

Below is sitemap.php and it is meant to be recognized as an XML sitemap (for SEO sake). The theory behind it is: It pulls all the links that are inside menu.inc and format them properly as an XML sitemap links.

<?php
    header ("Content-Type:text/xml");
    echo '<?xml version="1.0" encoding="UTF-8"?>
          <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
          http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'; ?>

<?php
  $url = "assets/includes/menu.inc";
  $input = @file_get_contents($url) or die("Could not access file: $url");
  $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
  if(preg_match_all("/$regexp/siU", $input, $matches, PREG_SET_ORDER)) {
    foreach($matches as $match) {
      // $match[2] = link address
      // $match[3] = link text
      echo '<url><loc>http://' . $_SERVER['SERVER_NAME'] . '/' . $match[2] . '.php</loc></url>';
    }
  }
  echo '</urlset>';
?>

It seems to be working fine, take a live look here: http://loaistudio.com/sitemap However, I am not really sure that it is recognized as an XML file - so I had it tested and the test fail - no site map found... Take a look here: http://seositecheckup.com/test_checkup/sitemap/42b50c824ac00c684c5368f9490a2dfe?url=www.loaistudio.com Please can anyone direct me to the right place? what I am doing wrong?

Was it helpful?

Solution

Perhaps this is a Rewrite issue??

RewriteRule ^sitemap.xml(.*)$ /sitemap.php?$1

with sitemap.php being the name of the php file that your code is saved within.

Also, and unrelated, you have within all of the loc paths:

filename.php.php

Pretty sure you will want to drop that .php you have hardcoded.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top