1

I have a sitemap named http://www.domain.com/sitemap1.php. It starts with this code:

<?php
echo '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="http://www.weddingpages.nl/sitemap.xsl"?><urlset 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/09/sitemap.xsd"        xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
';

After moving from Apache to Nginx Google webmaster tools started to refuse my sitemaps telling me that they look like HTML pages.

When looking at the output I saw something strange.

With Nginx:

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="http://www.weddingpages.nl/sitemap.xsl"?><head/><urlset 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/09/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

With Apache:

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="http://www.weddingpages.nl/sitemap.xsl"?><urlset 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/09/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

For some reason I do not understand Nginx throws in

<head/>

right before urlset.

Does anybody know the reason for this ? I am afraid this is what causes the problem. But even after searching I didn't find the answer.

  • Why does your sitemap have a stylesheet? – Rob Jul 5 '14 at 1:35
  • 1
    I doubt the problem is within nginx. However, show the complete nginx configuration so it can be confirmed. – Tero Kilkanen Jul 5 '14 at 1:38
  • Do you have xslt module enabled? – Alexey Ten Jul 5 '14 at 6:55
1

I do not know if it is right to answer my own question. But after some days I finally found the solution.

I want to thank Alexey Ten for mentioning the word "module". It seems the pagespeed module is the problem. Disabling pagespeed in the nginx configuration files solved the problem. I've read pagespeed only changes html so probably pagespeed thought this xml output was html. I enabled pagespeed again and added:

header('Content-Type: text/xml');

in the .php files. Now everything works allright. The strange thing is that I also used Apache with the pagespeed module and never had this problem. Probably there is a difference in pagespeed behaviour with Nginx compared to Apache.

  • This is why I asked why you had a stylesheet. Stylesheets should be in the head so I was wondering if something was trying to create a head element to put that in but sitemaps are machine read and have no need for a stylesheet. – Rob Jul 5 '14 at 12:36
  • I also don't understand why sitemaps have stylesheets. I just copied everything from someone else. But I do know that a lot of sitemap plugins for for example wordpress do use stylesheets, and lots of sitemap examples on the internet also use stylesheets. – Dimitri Visser Jul 5 '14 at 19:50

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.