Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

188
Visualizações
How to ignore sitemap url from Laravel routing?

I have sitemap.xml in the root directory of http://example.com

When I try to access http://example.com/sitemap.xml. It obviously throws route not found error.

So to try this changed .htaccess to look like:

Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/sitemap.xml
RewriteRule ^ index.php [L]

Laravel version in use: 5.1.

But, no luck. How can I just make use and render manually generated XML file rather than serving from route? I am not looking for complex XML parsing theory here. Just trying a hook to escape from the specific routing.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

The best approach is to move the sitemap.xml file to the public directory. You do not even have to worry about the routing as well.

Then it will automatically be accessible as http://example.com/sitemap.xml

over 4 years ago · Santiago Trujillo Relatório

0

You can create a route that returns the dynamically generated sitemap. You do not necessarily need to return a file.

Ex.:

Your routes:

Route::get('sitemap.xml', 'App\\Controllers\\SiteMapController@index');

Your SitemapController:

public function index()
{

    $urls = Logic::getMyUrlsToMap();
    return view('site.home.sitemap', compact('urls'));

}

Logic::getMyUrlsToMap() is your logic to search for the urls that will be mapped.

Your site.home.sitemap View:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    @if($urls)
        @foreach($urls as $url)
            <url>
                <loc>{{$url}}</loc>
            </url>
        @endforeach
    @endif
</urlset>
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda