Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow a specific PHP file to access a hardened wp-content folder

Tags:

php

.htaccess

1) My wp-content is hardened with a .htaccess file containing this code:

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

2) I want (need) to authorize xml-sitemap-xsl.php Otherwise I get this error in my error log: client denied by server configuration: /home/user/mysite.net/wp-content/plugins/wordpress-seo/css/xml-sitemap-xsl.php, referer: http://mysite.net/sitemap_index.xml

3) I think I should add the following code but I’m not sure if it’s the right code nor where to place it:

<Files "xml-sitemap-xsl.php">
Allow from all
</Files>

The thing I want to avoid is a conflict between the deny and allow commands.

Thanks,

P.

like image 969
Parneix Avatar asked Jan 14 '23 06:01

Parneix


1 Answers

This has not much to do with Wordpress and I am not an expert regarding .htaccess, but I believe that what your file is doing is not denying access to your directory by all .php files, rather, denying access to all the .php files inside the directory.

The <Files> directive is used to add specific rules to specific files and, as far as I know, it cascades.

Considering your comment, this should do the trick

<Files *.php> 
    deny from all
</Files>
<Files "xml-sitemap-xsl.php">
    Order Allow,Deny
    Allow from all
</Files>
like image 126
Sunyatasattva Avatar answered Jan 30 '23 21:01

Sunyatasattva