Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
Coppa WPB
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Come reindirizzare la pagina 404 alla pagina iniziale in WordPress

Nota editoriale: guadagniamo una commissione dai link dei partner su WPBeginner. Le commissioni non influenzano le opinioni o le valutazioni dei nostri redattori. Per saperne di più su Processo editoriale.

Volete reindirizzare la vostra pagina 404 alla vostra home page in WordPress?

Il reindirizzamento della pagina 404 “Non trovato” alla home page del vostro sito web può contribuire a ridurre il tasso di rimbalzo e consentire agli utenti di scoprire altri contenuti utili sul vostro sito.

In questo articolo vi mostreremo come reindirizzare la pagina 404 alla vostra home page in WordPress.

How to Redirect Your 404 Page to the Home Page in WordPress

Perché reindirizzare la pagina 404 alla home page di WordPress?

Quando un utente tenta di visitare una pagina che non esiste sul vostro sito WordPress, WordPress gli mostrerà invece una pagina di errore 404.

La formulazione e l’aspetto di questa pagina possono variare a seconda del tema utilizzato.

Default WordPress 404 page

La maggior parte degli utenti che approdano alla pagina 404 predefinita abbandonano rapidamente il vostro sito. Questo può aumentare la frequenza di rimbalzo complessiva e influire negativamente sul posizionamento nei motori di ricerca.

Per questo motivo è necessario dedicare del tempo alla creazione di una pagina 404 personalizzata. Tuttavia, finché non lo farete, potrete seguire la scorciatoia di questo tutorial e reindirizzare gli utenti alla homepage.

In un mondo perfetto, si dovrebbero anche reindirizzare le richieste di errore 404 specifiche alle pagine più pertinenti.

Detto questo, vediamo come reindirizzare tutti gli errori 404 alla vostra home page. Verranno illustrati due metodi e verrà mostrato come creare reindirizzamenti personalizzati per singole pagine:

Metodo 1: Reindirizzare tutti gli errori 404 alla pagina iniziale di WordPress

Per questo metodo, utilizzeremo All in One SEO for WordPress (AIOSEO). È il miglior plugin SEO per WordPress che consente di impostare redirect, ottimizzare i contenuti per i motori di ricerca e altro ancora.

La prima cosa da fare è installare e attivare All in One SEO (AIOSEO). Per maggiori dettagli, consultate la nostra guida passo-passo su come installare un plugin di WordPress.

Nota: esiste una versione gratuita di All in One SEO, ma noi utilizzeremo la versione Pro, poiché Redirect è un addon Pro.

Una volta attivato il plugin, è necessario andare in All in One SEO ” Reindirizzamenti.

Se non si sono ancora impostati i reindirizzamenti, è necessario fare clic sul pulsante “Attiva reindirizzamenti”.

Activating Redirects in All in One SEO

Questo installerà il modulo Redirects di All in One SEO.

Successivamente, è necessario fare clic sulla scheda “Impostazioni” nella parte superiore della pagina. Questa pagina consente di configurare i reindirizzamenti in AIOSEO.

The AIOSEO Redirects Settings Page

È necessario scorrere la pagina fino a trovare la sezione “Impostazioni avanzate 404”. Attivare questa sezione facendo semplicemente clic sul pulsante di attivazione in modo che diventi blu.

Ora si potranno vedere altre impostazioni. È necessario attivare il pulsante “Abilita reindirizzamento 404 predefinito”. Successivamente, assicurarsi che l’opzione “Pagina iniziale” sia selezionata.

Enabling Default 404 Redirect in AIOSEO

Si noti che esiste anche l’opzione “URL personalizzato”. Questa opzione consente di reindirizzare gli errori 404 a qualsiasi post o pagina. Non dimenticate di fare clic sul pulsante “Salva modifiche” nella parte superiore o inferiore della pagina per memorizzare le impostazioni.

Ora, quando i visitatori cercheranno di visitare un URL del vostro sito web che non esiste, saranno portati alla home page invece di vedere la pagina 404 predefinita.

Metodo 2: reindirizzare tutti gli errori 404 alla pagina iniziale utilizzando il codice

Se si preferisce non utilizzare un plugin, è possibile utilizzare un semplice snippet di codice per reindirizzare tutte le pagine 404 alla homepage.

Con questo metodo, è necessario aggiungere del codice ai file di WordPress. Se non l’avete mai fatto prima, consultate la nostra guida per principianti su come incollare snippet dal web in WordPress. Potreste anche consultare la nostra guida alla gerarchia dei modelli dei temi di WordPress.

Per prima cosa, è necessario creare un nuovo file nella cartella del tema di WordPress e nominarlo 404.php. Se il vostro tema ha già un file 404.php, dovete modificare quel file.

Per modificare questo file, è necessario collegarsi al proprio account di hosting WordPress con un client FTP o con lo strumento di gestione dei file.

FTP 404 php file

Una volta collegati al sito web, sarà possibile vedere il file 404.php nella cartella dei temi di WordPress.

È necessario aggiungere il seguente codice come prima riga del file 404.php:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
?>

Quindi, salvare il file 404.php e ricaricarlo nella cartella del tema utilizzando l’FTP o il pannello di controllo dell’hosting.

Ora, quando una pagina non viene trovata, invece di vedere una pagina 404, i visitatori saranno reindirizzati alla home page di WordPress.

Bonus: Impostare reindirizzamenti di pagina 404 personalizzati con AIOSEO

Il modo migliore e più SEO-friendly di gestire gli errori 404 è quello di reindirizzare i visitatori alla pagina più pertinente, non solo alla vostra homepage.

La funzione Redirects del plugin All in One SEO può anche tenere traccia di tutti gli errori di pagina 404 e consentire di impostare reindirizzamenti intelligenti di pagina 404 in WordPress.

Se avete installato e attivato AIOSEO quando avete seguito il Metodo 1, non dovete fare altro che tornare alla pagina All in One SEO ” Reindirizzamenti e cliccare sulla scheda “Impostazioni”.

Scorrete quindi verso il basso fino a visualizzare la sezione “Registri”. I log 404 sono un registro degli URL che i visitatori hanno cercato di utilizzare per visitare pagine che non esistono più sul vostro sito.

Assicurarsi che la voce “404 Logs” sia attivata in modo che appaia blu. È anche possibile scegliere per quanto tempo si desidera che il plugin registri i log, selezionando il periodo di tempo dal menu a discesa.

Enable 404 logs

Non dimenticate di fare clic su “Salva modifiche” prima di proseguire.

Successivamente, è possibile fare clic sull’opzione di menu “404 Logs” per visualizzare l’ultima pagina 404 consultata.

Tenere presente che, avendo appena attivato la registrazione, potrebbe non essere visualizzato subito nulla. Potrebbe essere necessario attendere fino a 24 ore prima di vedere qualche informazione utile.

Click 404 logs menu option

La colonna “URL” mostra le pagine che gli utenti hanno cercato di visitare ma che non esistono.

È possibile reindirizzare uno qualsiasi di questi URL a una pagina esistente facendo clic sul link “Aggiungi reindirizzamento” nella colonna “Reindirizzamento”. Si aprirà una tendina in cui inserire le informazioni sul reindirizzamento.

Per ottenere risultati ottimali, è necessario inserire la pagina più rilevante per la query originale nella casella “URL di destinazione” e poi fare clic su “Aggiungi reindirizzamento”.

Add home page redirect

Ad esempio, se avete cancellato un tutorial su come aprire un blog WordPress e poi ne avete scritto uno nuovo, è meglio reindirizzare il vecchio URL al nuovo post del blog piuttosto che alla vostra homepage.

Per aggiungere più reindirizzamenti a pagine 404, è sufficiente seguire la stessa procedura descritta sopra.

Ricordate che, in genere, non è consigliabile reindirizzare la pagina 404 alla home page per sempre. È un’ottima soluzione temporanea finché non si crea un design personalizzato della pagina 404 che converta meglio o si impostano reindirizzamenti individuali che portano gli utenti a una pagina pertinente che esiste.

Guide di esperti sugli errori 404 in WordPress

Ora che sapete come reindirizzare la pagina 404 alla vostra home page in WordPress, potreste voler vedere altre guide su come gestire gli errori 404.

Speriamo che questo articolo vi abbia aiutato a capire come reindirizzare la vostra pagina 404 in WordPress. Potreste anche voler consultare la nostra guida definitiva alla SEO di WordPress e i migliori costruttori di pagine WordPress drag-and-drop per creare pagine 404 personalizzate.

Se questo articolo vi è piaciuto, iscrivetevi al nostro canale YouTube per le esercitazioni video su WordPress. Potete trovarci anche su Twitter e Facebook.

Divulgazione: I nostri contenuti sono sostenuti dai lettori. Ciò significa che se cliccate su alcuni dei nostri link, potremmo guadagnare una commissione. Vedi come WPBeginner è finanziato , perché è importante e come puoi sostenerci. Ecco il nostro processo editoriale .

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Il kit di strumenti WordPress definitivo

Ottenete l'accesso gratuito al nostro kit di strumenti - una raccolta di prodotti e risorse relative a WordPress che ogni professionista dovrebbe avere!

Reader Interactions

66 commentiLascia una risposta

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Ralph says

    I have 2 or 3 blog posts that had to be deleted, but the urls are still present on Pinterest, forums, etc., so I redirected 404 to my homepage in hosting settings to not lose traffic. However, for any other non deleted 404 I have my own “sorry” info and search bar.
    I really appreciate good 404s on people’s websites, as this often indicates that they really care. Redirecting to the homepage has its uses, but not every time I think.

  3. Jiří Vaněk says

    I think, but it’s just my personal opinion, that redirecting people to the homepage isn’t good. Instead, it’s better to create a humorous 404 with an apology that reduces visitor frustration and offers interesting content in the form of a 404 page where the latest content of the website or blog can be automatically inserted. This way, the visitor realizes the page no longer exists but also gets the opportunity to laugh at a well-crafted 404 page and receives alternative content as an option for what to do next.

    • WPBeginner Support says

      That is another option, it depends on the site and what type of content but both are valid options :)

      Admin

  4. Mbah Chinedu says

    Hello, the 301 redirect you do at php file in ftp, can’t I use a text to inform user that the page is going to redirect in some seconds and then allow it redirect. At least bounce rate still reduces, because google has no issue with soft 404 or 404 pages

    • WPBeginner Support says

      You can create a page like that if you wanted but we do not have a beginner-friendly method for creating that with PHP.

      Admin

  5. Mark Cavallo says

    very quick and easy trick – saved me a heap of time manualy redirecting with new website. thank you.

  6. Mudassir says

    Hello WPbeginner team,

    I am using Astra Pro and have already some code in my 404.php. Now my question is, where do I add the above code exactly? Should I remove all that existing code and add yours or how?

    Please help!

  7. Noble A. Ozogbuda says

    Hello please how can i modify this code to redirect all my 404s pages to a specific page, not homepage?

  8. Mohan says

    I have just installed it and did some redirection. I hope it works the way I expect. Anyway, its a nice plugin. Thanks for the helpful post about it.

  9. Jitendra Mahato says

    hi… i want to know that how to redirect the 404 page to a custom page.I want to do that in my blog. Thank you. Hoping your answer. I used this code and doing well.

  10. Drake Bliss says

    If you only want to redirect a specific url path, try this code below. First create a child theme if you do not have one and move 404.php to the the child theme.

    Edit the 404.php page in the child theme and paste this code into the very top of the 404.php page. You can insert more check for other paths you want to redirect,.

  11. yudi cahyadi says

    hi there…i’m using chid theme but it doesn’t exist 404 file,, how to creat 404.php file using child theme not in main theme to insert code ..

    thank you..

  12. Liem Hoang says

    Work perfectly! Thank admin so much, you have been saved my life. My website will no longer get error win WMT.

  13. Malindo My Id says

    wow thankyou so much,, did you know thats my site have been redirect from spammer, makes my eror page 404 found until 1240 not found url. and now I was redirect to my home age.. you are good boys.. thankyou.. I like this page,, so useful for many blogger ..

    Malindo My Id from Indonesia

  14. Shoaib says

    i read anywhere on web that 404s should not be redirected globally to the home page.

    whats your view ???

  15. Sid says

    Is there any way that I can redirect specific 404 pages. Like I created a custom post type and I just want to redirect 404 pages on that post type. Will that be possible?

  16. Kumar says

    This code is causing problem, when i post something new permalink gets shorten and does not contain complete post title.

    What shld i do?

  17. Miguel Guzman says

    I have 1,500 404’s that is because i started using dates on the url at the beginning when i started using WordPress. I changed the permalinks and that’s when the 404 started. is really hard when you have so many redirect to map them individually. its easier to re direct then all to home page.

  18. Riccardo says

    How can you redirect depending on the language the site is displaying?
    My website is in french and english, but when I use your code it goes only to one page for both languages.

    Thank you for your help!

    Riccardo

  19. slango20 says

    this is bad practice, very bad. If you have time to set up a wordpress site, you have time to put 404 Not Found into a 404.php at *least* instead of redirecting to the homepage with no explanation whatsoever

  20. P.D. says

    Does anyone know if the code works as well for multisite installations?

    If so, does the 404 page bounce to the subdomain / subfolder / subsite or the main or root domain / folder / site?

    • slango20 says

      those crawl “errors” are perfectly normal and don’t affect your site’s ranking, just like it’s not a good idea to reply to all sms with the same response just because you received a few spam sms

  21. Filip Hajek says

    There is a cool WP plugin “404 Redirected”, whoch captures 404s for you and let’s you redirect them easily.

    • Eric says

      Thanks for the comment! That helped me out a lot! The article’s has a good solution too but I don’t like messing with my code. Thanks again for the suggestion Flip!

      -Eric Out-

  22. Rakesh says

    It rocks!!! I used the code ( previously my theme given me a custom 404 page template, but I replaced with your few lines). Thank you.

  23. Julien says

    I am really not convinced by the relevance of this. 404 means the page doesn’t exist anymore, 301 is a permanent redirect. Those 2 errors do not mean the same for search engines.

    • Rootpak says

      I agree. I would not recommend redirecting all 404 pages to the home page. From SEO point of view it is not accepyable. It means that every not existing page was moved to home page. It can simply lead to problems how google sees your site.

  24. Andy Feliciotti says

    I use smart 404 extension and I must say it’s amazing, it’ll find a post with a similar URL and redirect to it

  25. Clark Wimberly says

    I should know better, but one time I created an infinite loop using something close to this. It was a site with few pages for mostly logged-in users, so I made my 404 template redirect to the user page. What I had forgotten is that I made my user page redirect to the 404 if you weren’t signed in. Totally my fault, and barely relevant, but there you go.

    • Editorial Staff says

      Hah that’s funny. The only reason why we wrote this code was for a small one-page site which where we didn’t want users to peek around too much. Some folks are just curious and they start running search or checking out feeds etc. So we disabled search, feeds, and redirected 404 to the homepage.

      Admin

Lascia una risposta

Grazie per aver scelto di lasciare un commento. Tenga presente che tutti i commenti sono moderati in base alle nostre politica dei commenti e il suo indirizzo e-mail NON sarà pubblicato. Si prega di NON utilizzare parole chiave nel campo del nome. Avremo una conversazione personale e significativa.