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 disabilitare l’esecuzione di PHP in alcune directory di 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 migliorare la sicurezza del vostro sito WordPress?

Gli hacker possono caricare malware sul vostro sito web nel tentativo di penetrarvi. La disabilitazione del codice PHP in queste directory impedirà l’esecuzione del malware.

In questo articolo vi mostreremo come disabilitare l’esecuzione di PHP in WordPress utilizzando il file .htaccess.

How to Disable PHP Execution in Certain WordPress Directories

Perché disabilitare l’esecuzione di PHP in alcune directory di WordPress?

Per impostazione predefinita, WordPress rende scrivibili alcune directory, in modo che voi e gli altri utenti autorizzati del vostro sito web possiate caricare facilmente temi, plugin, immagini e video sul vostro sito.

Tuttavia, questa funzionalità può essere abusata se finisce nelle mani sbagliate, ad esempio dagli hacker che possono usarla per caricare file di accesso backdoor o malware sul vostro sito WordPress.

Questi file dannosi sono spesso camuffati da file di base di WordPress. Sono per lo più scritti in PHP e possono essere eseguiti in background per ottenere pieno accesso a ogni aspetto del vostro sito web.

Sembra spaventoso, vero?

Non preoccupatevi. C’è una soluzione semplice per questo problema. È sufficiente disabilitare l’esecuzione di PHP in alcune directory in cui non è necessario. In questo modo, nessun file PHP verrà eseguito all’interno di quelle directory.

Vediamo come migliorare la sicurezza di WordPress disabilitando l’esecuzione di PHP tramite il file .htaccess.

Disabilitare l’esecuzione di PHP in alcune directory di WordPress utilizzando il file .htaccess

La maggior parte dei siti WordPress ha un file .htaccess nella cartella principale.

Questo potente file di configurazione serve a proteggere con una password l’area di amministrazione, a disabilitare la navigazione nelle directory, a generare una struttura di URL SEO-friendly e altro ancora.

Per impostazione predefinita, il file .htaccess si trova nella cartella principale del vostro sito WordPress, ma potete anche creare e utilizzare altri file .htaccess all’interno delle vostre directory interne di WordPress.

Per proteggere il vostro sito web da file di accesso backdoor, dovete creare un file .htaccess e caricarlo nelle directory /wp-includes e /wp-content/uploads del vostro sito.

È sufficiente creare un nuovo file sul computer utilizzando un editor di testo come Notepad su Windows o TextEdit su Mac. Salvate il file come .htaccess e incollate al suo interno il seguente frammento di codice:

<Files *.php>
deny from all
</Files>

A questo punto, salvare il file sul computer.

Quindi, dovete caricare questo file nelle cartelle /wp-includes e /wp-content/uploads sul vostro server di hosting WordPress.

È possibile caricarlo utilizzando un client FTP o l’applicazione File Manager nel cruscotto dell’account di hosting.

Upload htaccess file to your WordPress site

Una volta aggiunto il file .htaccess con il codice di cui sopra, si impedirà l’esecuzione di qualsiasi script PHP in queste directory.

Verifica della presenza di backdoor in WordPress con Sucuri

L’uso di questo trucco .htaccess aiuta a rafforzare la sicurezza di WordPress, ma non risolve il problema di un sito WordPress già violato.

Le backdoor sono abilmente camuffate e possono già essere nascoste in bella vista.

Se volete verificare la presenza di eventuali backdoor sul vostro sito web, dovete attivare Sucuri sul vostro sito.

Sucuri

Sucuri è il miglior plugin di sicurezza per WordPress sul mercato. Scansiona il vostro sito web alla ricerca di possibili minacce, codice sospetto, malware e vulnerabilità.

Inoltre, blocca efficacemente la maggior parte dei tentativi di hacking dal raggiungere il vostro sito web, aggiungendo un firewall tra il vostro sito e il traffico sospetto.

Soprattutto, se il vostro sito WordPress viene violato, Sucuri lo ripulisce per voi. Per saperne di più, potete leggere la nostra recensione di Sucuri, perché utilizziamo il loro servizio da anni.

Per saperne di più, consultate la nostra guida su come trovare e risolvere le backdoor in un sito WordPress violato.

Guide degli esperti su come migliorare la sicurezza di WordPress

Ora che sapete come migliorare la sicurezza di WordPress disabilitando l’esecuzione di PHP in determinate directory, potreste voler apprendere altre tecniche di sicurezza.

Ecco alcune delle nostre migliori guide per migliorare la sicurezza di WordPress:

Speriamo che questo articolo vi abbia aiutato a capire come disabilitare l’esecuzione di PHP in alcune directory di WordPress per rafforzare la sicurezza del vostro sito web. Potreste anche voler imparare come creare un indirizzo e-mail aziendale gratuito o vedere le scelte dei nostri esperti sui plugin WordPress indispensabili per far crescere il vostro sito.

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

40 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. Mrteesurez says

    I see this as a great form of securing a website by disabling PHP execution in folders. According to this article, only two directories are secured, what of others ? Have they secured naturally or hackers don’t need it during the attempt ?

    • WPBeginner Support says

      Other sections of your site’s files normally require stricter access or have php files that are required to work for your site to work.

      Admin

  3. Jiří Vaněk says

    Thanks for these safety tips. I have created an htaccess file and will upload it to FTP. I have a website on my own server, so the question of security is entirely up to me. Thanks for the next step in making my WordPress a little more secure again.

  4. Unarine Leo Netshifhefhe says

    I also have this alert on my Updraft plugin where backups are not happening can this be due to htaccess?

    “Backup directory could not be created…

    The folder exists, but your webserver does not have permission to write to it. You will need to consult with your web hosting provider to find out how to set permissions for a WordPress plugin to write to the directory. (wp-content/updraft)”

  5. Brian Prom says

    FYI: you have a typo in your code snippet for the .htaccess snippet.

    Using your code snippet as is (without the closing /) breaks image loading.

  6. Vitor Gonçlaves says

    I’ve found some .php files in the uploads folder created by plugins. Can I assume this won’t cause a problem, or do I have to analyse each plugin individually?

  7. Suman Samanta says

    Great writing! You have a flair for informational writing. Your content has impressed me beyond words. I have a lot of admiration for your writing. Thank you for all your valuable input on this topic.

    • WPBeginner Support says

      Hey Thato,

      You can download your .htaccess file to your computer as a backup and then delete it from your website. Go to WordPress admin area Settings » Permalinks and click on the save changes button. This should regenerate your .htaccess file.

      Admin

  8. Shawn Rebelo says

    Do not do wp-content.
    Do wp-content/uploads.

    And this:

    order allow,deny
    deny from all

    May very on servers.

  9. Hardik says

    Does it affect the uploads file to upload on webpages?
    I found that after uploading this htaccess file to the folder many of images from many posts are not displaying.

  10. Chuck Cochems says

    Yeah, denying access to php files in the includes directory breaks the site because including actually obeys .htaccess restrictions.

    But the restriction on the uploads directory is very smart, and this should be there .BY DEFAULT in the uploads directory, and there’s no good reason for it not to be present.

  11. KOnnie says

    ZOMG! can’t you just disable write access to /wp-includes folder?
    Why fight with consequences when you can prevent the cause?

  12. Jeff Wigal says

    You can also put this in your Apache virtualhost, which will accomplish the same thing:

    Order allow,deny
    Deny from all

  13. anton says

    how to implement this code if we have combination of lower case and upper case on file extention for example on.php on my website its work but it s not working if the file named with.PHp ,.PHP .PhP or combination of them,the backdoor script still executed

    Thank you

  14. Shams says

    Hi Syed,
    Thanks for such an informative post and in fact it provides a great solution for saving WordPress from hackers.

  15. Ramon says

    I created an .htaccess file in the wp-includes folder. Site looked oke but my WYSIWYG editor in the admin pages wasn’t working. Had to remove the .htaccess file again. (WP 3.9.1)

  16. Wes says

    I also found my wp-includes folder full of php files and I can’t see how using that .htaccess file in there wouldn’t break something. I did use it in the uploads dir.

  17. Red says

    forgive my bad english…
    i followed all your instructions in this article, but when i go my dashboard to add a newpost, my post section was messed up. … i suspect the .htaccess was the problem.
    when i deleted it, the post was fine.

  18. Brad says

    I tried this in my /wp-includes/ directory, which is full of php files. Of course I could no longer access the site. Did you really mean to include the includes directory for use with the .htaccess file?

    Did you maybe mean /wp-includes/images ?

    • Editorial Staff says

      Nope. We meant /wp-includes/ folder. We have this on our wp-includes folder. If for some reason it is breaking your site, then delete the .htaccess file from your wp-includes folder.

      Admin

      • Brad says

        Strange, my wp-includes folder has over 90 php files in it. And it does break the site. I took it back out immediately.

        But I did put it in the /wp-content/uploads/ folder and its works just fine there. Thanks for responding

        • Alfred says

          Putting an htaccess file denying access to php files in a directory full of php files does seem rather odd. I assume it’s because these files are normally only included, not executed directly. If that’s true, wouldn’t it be better to just deny access to the entire directory?

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.