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.
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.
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 è 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:
- La guida definitiva alla sicurezza di WordPress (passo dopo passo)
- Come eseguire un controllo di sicurezza di WordPress (lista di controllo completa)
- Come scansionare il vostro sito WordPress alla ricerca di codice potenzialmente dannoso
- I migliori scanner di sicurezza per WordPress per il rilevamento di malware e hack
- Come aggiungere l’autenticazione a due fattori in WordPress (metodo gratuito)
- Come aggiungere domande di sicurezza alla schermata di login di WordPress
- Cosa, perché e come delle chiavi di 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.
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!
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
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.
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)”
WPBeginner Support says
That looks to be a file/folder permissions issue, you would want to reach out to your hosting provider and they can help, you can also take a look at our guide below:
https://www.wpbeginner.com/beginners-guide/how-to-fix-file-and-folder-permissions-error-in-wordpress/
Admin
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.
WPBeginner Support says
Thank you for pointing that out, our code should be fixed
Admin
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?
WPBeginner Support says
If you reach out to your plugins they can let you know the specifics for those files.
Admin
nirbo says
Thanks for the information
WPBeginner Support says
You’re welcome
Admin
cliff denney says
thank you very much
WPBeginner Support says
You’re welcome
Admin
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
Thank you, glad you enjoy our writing
Admin
Thato says
Guys i think i have messed up my htaccess file, my website is completely not displaying images
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
Shawn Rebelo says
Do not do wp-content.
Do wp-content/uploads.
And this:
order allow,deny
deny from all
May very on servers.
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.
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.
Stan says
What’s the method for IIS servers?
Thanks,
KOnnie says
ZOMG! can’t you just disable write access to /wp-includes folder?
Why fight with consequences when you can prevent the cause?
Jonathan Hodgson says
Wouldn’t this stop wordpresss being able to update the files in core updates?
Jeff Wigal says
You can also put this in your Apache virtualhost, which will accomplish the same thing:
Order allow,deny
Deny from all
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
Timothée Moulin says
You can put this in your .htaccess file
Order Deny,Allow
Deny from All
Shams says
Hi Syed,
Thanks for such an informative post and in fact it provides a great solution for saving WordPress from hackers.
Vladimir says
Hi!
I followed all your instructions in this article, but Its not working…
Thanks
Aurélien Debord says
A so useful post with such good and quick tips.
Thanks
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)
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.
Editorial Staff says
It does break it sometimes (depending on the plugin you are using), but not all the time.
Admin
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.
Editorial Staff says
Which directory did you upload the .htaccess file that caused this issue?
Admin
Chris says
I added the .htaccess file to my wp-includes and didn’t have any problems. Thanks a lot of the tips.
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?