This is my code in Laravel :
SitemapGenerator::create('https://'.request()->getHost())->writeToFile(request()->getHost().'.xml');
After generating the sitemap I am getting this type of URLs
<url>
<loc>https://example.com/login?redirectTo=https://example.com/posts/wvj/test</loc>
<lastmod>2021-01-20T19:39:59+06:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>
Thanks
Use add method.
SitemapGenerator::create('https://example.com')
->getSitemap()
->add(Url::create('/extra-page')
->setLastModificationDate(Carbon::yesterday())
->setChangeFrequency(Url::CHANGE_FREQUENCY_YEARLY)
->setPriority(0.1))
->add(...)
->writeToFile($path);
Related
sitemap.xml not work in my host:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://tcg-wallet.ga/</loc>
<lastmod>2022-12-13T17:12:22+00:00</lastmod>
</url>
</urlset>
located in public, and loaded via: https://tcg-wallet.ga/sitemap.xml
in network i see this:
but when i try to get it working in google search i get this:
i have test it with: https://www.xml-sitemaps.com/ and get this:
i have try handle the content type with .htaccess but is not enough to solve the problem:
<IfModule mod_expires.c>
AddType application/xml xml
</IfModule>
I can't find that it is misconfigured.***
I am developing a Laravel application. Now, I am trying to implement the sitemap for my website using this package, https://github.com/spatie/laravel-sitemap. But when I generate sitemap.xml, no paths are included in the file.
I installed the package running the Composer command
composer require spatie/laravel-sitemap
Then I published the Composer.
php artisan vendor:publish --provider="Spatie\Sitemap\SitemapServiceProvider" --tag=config
In the routes/web.php, I added this.
Route::get('sitemap', function () {
SitemapGenerator::create('http://app.localhost/')->writeToFile('sitemap.xml');
return "Sitemap generated".
});
When I run the code and sitemap.xml is generated. When I opened the sitemap.xml, that is all I found in it.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
</urlset>
I have many routes in the web.php. What is wrong and how can fix it?
You can manually add other urls like below and when you run it, the links will be added to your sitemap file:
use Spatie\Sitemap\SitemapGenerator;
use Spatie\Sitemap\Tags\Url;
Route::get('sitemap', function () {
SitemapGenerator::create('https://vesicash.com/')->getSitemap()
->add(Url::create('/link1')->setPriority(0.5))
->add(Url::create('/link2')->setPriority(0.5))
->add(Url::create('/link3')->setPriority(0.5))
->add(Url::create('/privacy')->setPriority(0.5))
->writeToFile('sitemap.xml');
return "Sitemap Generated";
});
This is how I solved this problem:
I just made sure that the APP_URL was set properly in .env file.
I added, for example: https://example.com/ and boom it worked.
This should also work on your local pc as well.
When I did it first time it looked same for me.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
</urlset>
I think you did it on your local pc.
So first, you can test with this url.
SitemapGenerator::create("https://spatie.be/en")
->writeToFile(public_path('sitemap.xml'));
If it works well, then I believe it will work on server too.
In my case it worked on server, while it was same result with you on my local.
I have created a Package in laravel and i am not able to include the package between header and footer of the page. Please find the code below,
$this->loadViewsFrom(__DIR__.'\views','details');
How to include the package between header and footer section of a website ?
Please help me to resolve the issue.
The package have the following structure as show below
--Root
--packages
--events
--details
--src
--assets
--Models
--Request
--Views
routes.php
DetailsServiceProvider.php
DetailsController.php
composer.json
In your service provider you will register a view namespace using the code:
$this->loadViewsFrom(__DIR__.'\relative\path\from\service-provider','details');
Now you would be able to load files using view('details::template-file') which will look for the path \relative\path\from\service-provider\template-file.blade or by including them in other blade files: #include('details::template-file')
( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Call to a member function toHtml() on a non-object in C:\wamp\www\app\code\core\Mage\Core\Model\Layout.php on line 555
Installed Magento 1.7 and WAMP 2.2 and a custom template. Magento admin works perfect but the frontend gives the above errors.
Page.xml in magento 1.7 installation and the custom template doesn't have the following code at all and therefore, didn't try the following fix :
<block type="core/profiler" output="toHtml"/>
would become:
<block type="core/profiler" output="toHtml" name="core_profiler"/>
After changing:
<block type="core/profiler" output="toHtml"/>
to
<block type="core/profiler" output="toHtml" name="core_profiler"/>
in page.xml under app/design/frontend/base/default/layout (or your custom page.xml)
either:
refresh the cache in Layout building instructions from admin or
delete contents of /var/cache folder, which is located at root of your magento folder
Okay, what is happening!? I switched to pretty urls using code igniter; http://robertwaynehq.com/what-we-do rather than the same with .php
I then updated the site map file and it doesn't seem to like that the pages have no extension. Further the google webmaster site is giving a redirect error. Yet the pages work. Help?
Edit: I do have the redirects in the old files.
<?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://mydomain.com/what-we-do" );
?>
The real issue is that I have updated the sitemap.xml and google webmaster tools doesn't seem to like or recognize the files.
<?xml version="1.0" encoding="UTF-8"?>
<urlset>
<url>
<loc>http://mydomain.com/</loc>
<changefreq>weekly</changefreq>
</url>
<url>
<loc>http://mydomain.com/index.php</loc>
<changefreq>weekly</changefreq>
</url>
<url>
<loc>http://mydomain.com/what-we-do</loc>
<changefreq>weekly</changefreq>
</url>
<!-- and so on for each page... -->
</urlset>
set 301 redirect in the old php files, redirecting to the url of the page
Google Webmaster Tools help on 301 Redirect
301 Redirect in PHP