RavanH / xml-sitemap-feed

XML Sitemap & Google News feeds
GNU General Public License v2.0
16 stars 21 forks source link

I Installed the Plugin but It’s Giving Me an Error When I View the Sitemap #42

Closed revolutionnaire closed 1 year ago

revolutionnaire commented 1 year ago

Hi! I like this plugin because it's so simple and unintrusive to the WordPress UI. Please help me to get it to work. I'm encountering an error when I view the site's XML sitemap: error on line 18 at column 1: ParsePI: PI php never end. I'm not sure if it's my site or the plugin's fault.

RavanH commented 1 year ago

Hi, could you share the URL where the error occurs? Or, if it is on the main /sitemap.xml for example, please try /index.php?feed=sitemap to see if it occurs there too...

revolutionnaire commented 1 year ago

It's suddenly working now. Weird.

Anyway, thanks! The plugin's really awesome!

revolutionnaire commented 1 year ago

Sometimes, the XML is generated properly. Sometimes, it's blank. I'm not sure exactly what to do.

RavanH commented 1 year ago

Hi, if your XML sitemap appears blank in the browser, it might be a problem with the XSL stylesheet file. This, in itself, is not a problem for search engines (they ignore the stylesheet completely) but it will make your browser show a blank page.

You can verify this by typing Ctrl+U (or Option+Command+U in Safari) to view the source code. If you see code starting with <?xml version=... then you can safely say the problem is not with the sitemap itself but with the stylesheet...

revolutionnaire commented 1 year ago

It's not loading the XML version of the page either. There's only the empty body element along with the Grammarly plugin's markups. I have a plugin to check grammar and spelling.

Here's what the source code looks like: <html><head></head><body data-new-gr-c-s-check-loaded="14.1113.0" data-gr-ext-installed=""></body><grammarly-desktop-integration data-grammarly-shadow-root="true"></grammarly-desktop-integration></html>

revolutionnaire commented 1 year ago

Sorry for the trouble. I really appreciate you taking the time to help me fix this.

RavanH commented 1 year ago

Grammarly? Is that a browser extension? If so, it appears to be injecting HTML that will break any XML... Is there an option to turn that off on certain URLs?

You could use an external XML or sitemap validator to see if your sitemap can be read from the outside without any browser extensions interfering... Try https://www.w3schools.com/xml/xml_validator.asp or https://www.xml-sitemaps.com/validate-xml-sitemap.html

Have you got a Google Search Console account? If so, add your XML sitemap there to see if any errors are reported.

revolutionnaire commented 1 year ago

Yup, it's a browser extension. I turned it off in the meantime and it's still giving me an empty HTML page but when I used the xml-sitemaps.com it said no issues detected. Sorry, I forgot to mention but the thing that prompted me to do this is when I added the sitemap to the Google Search Console and it said it has errors. This is the exact message: Sitemap can be read, but has errors. Sitemap is HTML. Your Sitemap appears to be an HTML page. Please use a supported sitemap format instead.

RavanH commented 1 year ago

So somehow your WP installation or hosing provider is returning HTML instead of XML in the sitemap URL. And apparently his does not happen every time but only sometimes... Is there any pattern that you can find, that would allow us to reproduce the issue consistently?

Have you tried tried to use the external validators multiple times? Maybe quickly repeating multiple validations, triggering a firewall error response?

Or are you using a CDN like Cloudflare that sometimes has trouble connecting to your site? Or maybe your hosting provider is being overloaded? This can happen sometimes but should not be happening very regularly...

You can send me the sitemap URL via https://status301.net/contact/ and I can do some external testing if you wish :)

revolutionnaire commented 1 year ago

I honestly don't know what patterns to look for. Can you tell me more about this?

I tried using xml-sitemaps.com again and this time it failed with the same error that Google Search Console gave me. It's loading an HTML file. I guess it's happening randomly.

As far as I know, I'm not using a CDN. How do I know my hosting provider is being overloaded?

I just sent you an email using the contact form you provided. I really appreciate that you're taking the time to help me with this.

RavanH commented 1 year ago

Hi, yes got the e-mail. From my side, the sitemap is responding with an HTML "Website Under Construction" message...

revolutionnaire commented 1 year ago

I'm using the Maintenance Mode plugin. Is it causing any conflict with the sitemap? I tried disabling Maintenance Mode but it's still giving me a blank page for the sitemap.

RavanH commented 1 year ago

Yes, Maintenance Mode is blocking public access to all content of your site, including the sitemap. Is there an option to exclude certain URLs from being blocked in your Maintenance Mode plugin?

revolutionnaire commented 1 year ago

There is but the path to sitemap.xml isn't in the options. I tried deactivating the plugin this time and it worked. It wasn't a blank page but it's an HTML version of the sitemap. Is that normal?

revolutionnaire commented 1 year ago

Sorry, it's a blank page again. I tried loading the sitemap again while the plugin is deactivated.

revolutionnaire commented 1 year ago

This is weird. I am now using a different Maintenance Mode plugin. I tried doing a hard refresh and every time I do it, it loads properly but when it's a normal refresh, it's just a blank page.

RavanH commented 1 year ago

Yes, I see that the first request is working but then, the second one gives a blanc result. You can try this by appending the sitemap URL like /sitemap-news.xml?XYZ. Change that XYZ to any random sequence and hit Enter, then the sitemap loads. Then renew and you get an empty result. Change the random sequence after the question mark again and the same thing happens.

I can only conclude the sitemap is being generated correctly but there is something going wrong with the response headers and caching. I think it is the combination of the Etag that is added by your Litespeed server and one of the response headers that is coming from the plugin itself. I'll try to find out more...

revolutionnaire commented 1 year ago

Thanks!

RavanH commented 1 year ago

Update: would you be willing to do a little test for me? It involves a small modification to one of the plugin files. The steps are as follows:

  1. Go to Plugins and deactivate the XML Sitemap & Google News plugin.
  2. Then go to Tools > Plugin File Editor, select "XML Sitemap & Google News" in the dropdown on the top right side and hit the Select button.
  3. Now, under "Plugin Files" on the right side, find and open (click) the file models > functions.public-shared.php
  4. Next, on line 13 of that file you should see $headers['Status'] = '200';
  5. Place two slashes in front of that so il will look like //$headers['Status'] = '200';
  6. Hit the Update File button at the bottom.
  7. Go back to Plugins and re-activate the XML Sitemap & Google News plugin.

Let me know so I can test your sitemap again :)

Note: If you get an error after trying to re-activate the plugin, then something went wrong during the modification. Just uninstall the complete plugin and re-install it to get it back as it was before.

revolutionnaire commented 1 year ago

No problem. I've made the changes you asked.

RavanH commented 1 year ago

OK, that seems to be working. Try /sitemap.xml?test123 for example and reload a few times. From my side that generates the full sitemap in the browser. To get it working for the normal /sitemap.xml URL, you ill need to clear your browser cache because it has cached an empty response. Or you can open an Anonymous/Incognito/Private browser window and try...

revolutionnaire commented 1 year ago

It works! Thank you so much!

I suppose I should keep the change we made to the file earlier?

RavanH commented 1 year ago

Yes, you can keep the change. I'll be adding this fix to the next release :)

Thank you for your cooperation and bug report!

revolutionnaire commented 1 year ago

No problem. You actually fixed it. Thanks again!