2

I have written a sitemap with the help of https://laravel-news.com/laravel-sitemap

here is my index :

public function siteMap(  )
{
    $news=News::orderBy('time','desc')->where('time','<',time())->where('showview',1)->first();
    $categories = Cat::orderBy('id' , 'desc')->first();
    $games = Game::orderBy('id' , 'desc')->first();
    $genres = Genre::orderBy('id' , 'desc')->first();
    $movies = Movie::orderBy('id' , 'desc')->first();
    $platforms = Platform::orderBy('id' , 'desc')->first();

    return response()->view('siteMap.siteMap', [

        'news'          =>  $news,
        'categories'    =>  $categories,
        'games'         =>  $games,
        'genres'        =>  $genres,
        'movies'        =>  $movies,
        'platforms'     =>  $platforms

    ])->header('Content-Type', 'text/xml');
    }

and my blade :

<?php

echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>

{{-- site map for posts --}}
<sitemap>
    <loc> //url /{{ $news->id }}/{{ $news->title }}</loc>
    <lastmod>{{ date('c',$news->time) }}</lastmod>
</sitemap>

{{-- sitemap for categories --}}
<sitemap>
    <loc>//url/{{ $categories->id }}/{{ $categories->name }}</loc>
    <lastmod>{{ date('c',  $categories->time) }}</lastmod>
</sitemap>

{{-- sitemap for games profile --}}
<sitemap>
    <loc>//url/profiles/games/{{ $games->id }}/{{ $games->name }}</loc>
    <lastmod>{{ date('c', (integer) $games->time) }}</lastmod>
</sitemap>

{{-- sitemap for genres profile --}}
<sitemap>
    <loc>//url/{{ $genres->id }}/{{ $genres->name }}</loc>
    <lastmod>{{ date('c',  $genres->time) }}</lastmod>
</sitemap>

{{-- sitemap for movie profile --}}
<sitemap>
    <loc>//url/{{ $movies->id }}/{{ $movies->name }}</loc>
    <lastmod>{{ date('c',  (integer) $movies->time) }}</lastmod>
</sitemap>

{{-- sitemap for platforms profile --}}
<sitemap>
    <loc>//url/{{ $platforms->id }}/{{ $platforms->name }}</loc>
    <lastmod>{{ date('c', (integer) $platforms->time) }}</lastmod>
</sitemap>

after uploading on host and using google webmaster i get below error :

Your Sitemap appears to be an HTML page. Please use a supported sitemap format instead.

thanks for your help !

Amir Jani
  • 380
  • 6
  • 16
  • Make sure the route has xml as the extension `Route::get('sitemap.xml'...`. Don't forget the sitemapindex ` – aynber May 22 '18 at 17:43
  • Sidenote, you can use `{!! !!}` instead of ` – Tim Lewis May 22 '18 at 17:44
  • @aynber after checking browser I post this question and pretty sure the problem is not the routes . Thanks – Amir Jani May 23 '18 at 15:57
  • @Amir_Jani did you fix this? I'm getting the same error from google search console while splitting my sitemaps with sitemapindex. I haven't add response `text/xml` yet, cause the old sitemap action didn't have it. – KeitelDOG Apr 16 '20 at 01:13
  • @KeitelDOG I don't remember how I fixed this one, but I've got my answer from ericlbarnes in laracast https://laracasts.com/discuss/channels/laravel/seo-with-laravel-and-cast-to-xml – Amir Jani Apr 19 '20 at 06:03
  • @Amir_Jani thank you. I've fixed it, and i think it was more like a cache problem may be in the new Google Search Console. It was recommended to delete the sitemap first before submitting again. So what I did was to delete it, and submit a new sitemap uri cause I changed it's structure for sitemapindex. And it worked. – KeitelDOG Apr 19 '20 at 15:36

0 Answers0