Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

adriansio's avatar

Keeping sitemap.xml across releases

Hey guys, I'm using Envoyer and I have a scheduled commands that runs daily to generate a sitemap.xml in the /public folder of my app.

The problem is the Envoyer wipes out the /public folder completely as you might know and every time I have to regenerate the sitemap.xml after every commit, which is not ideal.

Any suggestion?

0 likes
3 replies
click's avatar

Try it with the symbolic link option php artisan storage:link. This creates a symbolic link from storage/app/public to public/storage.

https://laravel.com/docs/5.6/filesystem#the-public-disk

Now you should store your sitemap in /storage/app/public. And it will be accessible from https://yourdomain.com/storage/sitemap.xml.

Or if you do not want the storage prefix in the url. You could create your own symlink on the command line:

ln -s /path/to/laravel/storage/sitemap.xml /path/to/laravel/public/sitemap.xml

Now you should store your sitemap in the storage directory and it will be accessible from https://yourdomain.com/sitemap.xml

1 like
adriansio's avatar

@m-rk Thank you for your answer. Yes that's what I thought too, I just didn't like to have the storage prefix in the url. And yes, it seems the only way is to use symlinks.

Do you think I should create the symlink in the development environment and commit it or just create it on production?

click's avatar

Symlinks are not part of your code. It it something of the operating system. So you should do it on your production server.

An alternative solution that I use at this moment because I run multiple sites on the same application is to create a route called sitemap.xml that resolves to SitemapController.php and inside that controller I search for the sitemap in my storage directory and return the file if it exists. This is slower than a symlink but this works good for me.

Route::get('sitemap.xml', 'SitemapController@index');
class SitemapController extends Controller
{
    public function index()
    {
        $path = site()->key . '/sitemap.xml';
        if (!Storage::disk('local')->exists($path)) {
            return response()->redirectTo('/');
        }

        // get the sitemap and check if it has content
        $xml = Storage::disk('local')->get($path);
        if (!$xml) {
            return response()->redirectTo('/');
        }

        // get the xml from the storage and present it
        return response($xml, 200, ['Content-Type' => 'text/xml']);
    }
}
1 like

Please or to participate in this conversation.