Php 网站地图甚至没有找到它在那里

Php 网站地图甚至没有找到它在那里,php,html,xml,sitemap,Php,Html,Xml,Sitemap,下面是sitemap.php,它被认为是一个XML站点地图(为了SEO)。 其背后的理论是:它提取menu.inc中的所有链接,并将它们正确格式化为XML站点地图链接 <?php header ("Content-Type:text/xml"); echo '<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/site

下面是sitemap.php,它被认为是一个XML站点地图(为了SEO)。 其背后的理论是:它提取
menu.inc
中的所有链接,并将它们正确格式化为XML站点地图链接

<?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>';
?>


也许这是一个重写问题

RewriteRule ^sitemap.xml(.*)$ /sitemap.php?$1
其中sitemap.php是保存代码的php文件的名称

此外,在所有loc路径中,您都有:

filename.php.php

非常肯定您会想删除您硬编码的.php。

谢谢您,我是否需要添加此规则?请检查我这里的当前.htaccess文件:应该能够将这行代码插入htaccess文件的底部,然后就可以开始了。显然,如果您将文件命名为其他名称,则需要更改“站点地图”文件名。