Abdul Wadood
Abdul Wadood

Reputation: 134

Adding Sitemap file and route in laravel

I have a sitemap.xml file in my view folder and this is the route:

Route::get('sitemap.xml',function() {
return response()->view('sitemap')
->header('Content-Type', 'xml');
});

But when i search mydomainname.com/sitemap.xml. It returns InvalidArgumentException View [sitemap] not found.

I tried to search on google and youtube but not able to find any solution.

Upvotes: 2

Views: 7443

Answers (4)

hom srieng
hom srieng

Reputation: 1

1.Move sitemap.xml to folder view
2.Rename sitemap.xml to sitemap.php
3.Create route by code below:

Route::get('sitemap.xml',function() {
return response()->view('sitemap')->header('Content-Type', 'xml');});

Upvotes: 0

Muhammad Tarique
Muhammad Tarique

Reputation: 1437

Just put your sitemap to public folder and hit the http://yourdomain.com/sitemap.xml

Upvotes: 1

Jsonx
Jsonx

Reputation: 81

Just move your sitemap.xml to public directory. It doesn't need any Route.

Upvotes: 7

Abdul Wadood
Abdul Wadood

Reputation: 134

I moved sitemap.xml file to the public directory and the route would be:

Route::get("sitemap.xml" , function () {
return \Illuminate\Support\Facades\Redirect::to('sitemap.xml');
 });

Now open the xml file through url: www.domain.com/sitemap.xml

Upvotes: 4

Related Questions