Sitemap.xml is Not Being Served Correctly
-
Issue: Sitemap.xml is Not Being Served Correctly on Hostinger with Laravel Setup
Environment:Hosting Provider: Hostinger
Project Type: Laravel (Bagisto)
Website URL: devsamagri.com
Directory Structure:
public_html/ (Root directory)
public_html/public/ (Laravel's public directory)
Problem Description:I’m encountering an issue where my sitemap.xml is not being served correctly. Instead of being displayed as an XML file, it’s being treated as an HTML page, resulting in the error: "Your Sitemap appears to be an HTML page. Please use a supported sitemap format instead."
What I’ve Tried:
Generated the Sitemap:Created a sitemap.xml using xml-sitemaps.com.
Uploaded the sitemap.xml file to both public_html/ and public_html/public/ directories.
.htaccess Configuration:I have the following .htaccess setup in public_html:
apache
Copy code
RewriteCond %{HTTP_HOST} ^devsamagri.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.devsamagri.com$
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L]Serve sitemap.xml as an XML file
<FilesMatch "^sitemap.xml$">
ForceType application/xml
Header set Content-Type "application/xml"
</FilesMatch>Serve sitemap_index.xml as an XML file (if applicable)
<FilesMatch "^sitemap_index.xml$">
ForceType application/xml
Header set Content-Type "application/xml"
</FilesMatch>Handle all other Laravel routes in the public folder
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/index.php [QSA,L]
Outcome:The sitemap.xml file at https://devsamagri.com/sitemap.xml is served correctly and recognized by search engines.
However, other URLs such as https://devsamagri.com/sitemap.php or any other dynamically generated sitemaps are not being served correctly—they return the home page or a text/html content type instead of application/xml.
Request:
I need assistance with:Ensuring that all sitemap URLs are served with the correct Content-Type: application/xml.
Maintaining the existing Laravel routing and redirection rules.
Any guidance or solutions to resolve this issue would be greatly appreciated. Thank you! -
Hello @tribhuvanabhi
I think you are doing some customization because by default there is no page like this.
https://devsamagri.com/sitemap.php
And if the page didn't exist how it will go to homepage.
The correct page is sitemap.xml
Thanks & Regards