All page with 404 redirect to homepage

Hello everyone. Help me figure out the problem. Can’t redirect all non-existent pages(error page) to homepage. Adding to Nginx config does not help. I’ve tried everything. As far as I understand, you can do a manual redirect in the site.yaml config but how?

    /error: '/'

not work

Can I ask why you want to do this? 404 pages have a very clear and useful purpose. It might seem helpful to users, but simply redirecting them will have all kinds of unintended effects.


My site doesn’t need a 404 page. I need a simple 301 redirect of any 404 page to the main page. This is a common practice that I implemented via nginx config or htaccess. But in this cms I encountered a problem that I cannot solve.

AFAIK this is far from common practice :thinking: Also you will have issues with SEO if any invalid link redirects to a home page - I believe crawlers would mark all such pages as duplicates :man_shrugging:

I’m not here about SEO issues :slightly_smiling_face:
I need help setting up a redirect. There was one similar topic on this forum, but there was no solution there either.

Hi, @SupaVlad, you can try the following:

  1. make sure the error plugin is enabled
  2. create a page template in your theme called error.html.twig
  3. put this code
    {% if http_response_code(404) %}
        {{ redirect_me(home_url, 301) }}
      {% else %}
        <h1>{{ 'PLUGIN_ERROR.ERROR'|t }} {{ header.http_response_code }}</h1>
        <p>{{ page.content|raw }}</p>
    {% endif %}
1 Like

You’re The Best
works like a clock

1 Like