Forum

Thread tagged as: Question, Error, Configuration

Google Sitemap

Having problems with the Google Sitemap solution posted in docs.

I have a sitemap.xml file with

<?php
    header('Content-type: application/xml');
    include('perch/runtime.php');
    perch_pages_navigation(array(
        'template' => 'sitemap.html',
        'flat'=>true
    ));
    perch_blog_custom(array(
        'template' => 'blog_sitemap.html',
        'flat'=>true
    ));
?>

I also have this in the .htaccess

AddType application/x-httpd-php .php .xml

And this in the template

<perch:before><?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
</perch:before>
<url>
    <loc>https://marketingalchemy.co.uk<perch:pages id="pagePath" /></loc>
</url>
<perch:after>
</urlset>
</perch:after>

When try to submit it to Google it has an error, so if I visit the xml page in a browser its says "This page contains the following errors: error on line 12 at column 3: Extra content at the end of the document"

However I cannot see an extra line, so any idea what I have done wrong?

Nigel Coath

Nigel Coath 1 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

It's not being parsed as PHP. If you view the file, you can see your PHP source.

Is that because of an error in my .htaccess?

I made some corrections, spotted my path to perch runtime is admin/runtime.php

And changed the .htaccess to AddType application/x-httpd-php .php .xml

Should this come after the RewriteEngine on line?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Right - you need to get the .xml parsing as PHP. I can't tell you how to do that as it depends on your server configuration.

I think the issue was the path to perch. Seems I had to add the / in front of the path for it to work.

include('/admin/runtime.php');

So it seems to load the xml now however its not finding anything:

"This XML file does not appear to have any style information associated with it. The document tree is shown below."

To recap I have this in my xml:

<?php
    header('Content-type: application/xml');
    include('/admin/runtime.php');
    perch_pages_navigation(array(
        'template' => 'sitemap.html',
        'flat' => true,
    ));
    perch_blog_custom(array(
        'template' => 'blog_sitemap.html',
    ));
?>

The main site map template is in /templates/navigation and the blog one in /templates/blog (tried moving this but made no difference).

Can you think why its not finding the pages?

Drew McLellan

Drew McLellan 2638 points
Perch Support

It's not returning anything - the result is an HTTP 500.

You're also running nginx, which would explain perhaps why those apache directives aren't working for you.

Okay cracked it. It was a rogue line at the top caused by having a line break.

Second problem was that having two templates for regular and blog content meant both had <urlset> and <?xml version="1.0" encoding="UTF-8"?>

I an attempt to fix this I have this in the main site map template:

<perch:before><?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">
</perch:before>
<url>
    <loc>https://marketingalchemy.co.uk<perch:pages id="pagePath" /></loc>
</url>

and this in the blog site map:

<url>
    <loc>https://marketingalchemy.co.uk<perch:blog id="postURL" /></loc>
</url>
<perch:after>
</urlset>
</perch:after>

Seems to work, however how do I exclude the urls for the blog section that point to /blog/index.php and /blog/detail.php?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You can exclude any pages by checking the box to hide them from navigation.

Ah ha so simple, thanks!!