.htaccess拒绝访问大多数XML文件

我最近有一个Joomla网站被黑客攻击,所以我试图强化这个网站。 推荐的.htaccess中有一部分限制了对扩展名附带的xml文件的外部访问。 但是,它也让我的sitemap.xml文件被访问。

如何在保留其余的情况下允许某个文件?

这是默认的代码:

<Files ~ "\.xml$"> Order allow,deny Deny from all Satisfy all </Files> 

和我的修改,导致500错误:

 <Files ~ "(?!sitemap)\.xml$"> Order allow,deny Deny from all Satisfy all </Files> 

FilesMatch行有一个额外的“<”。 它应该是:

 <FilesMatch "(?!sitemap)\.xml$"> 

您应该使用<FilesMatch>在这里logging

另外,我认为你的正则expression式应该是(?<!sitemap)\.xml$ 。 喜欢这个:

 <FilesMatch "(?<!sitemap)\.xml$"> Order allow,deny Deny from all </FilesMatch> 

我终于决定不要乱用正则expression式。

我补充说:

 <Files ~ "sitemap\.xml$"> Order allow,deny Allow from all </Files> 

之后,它就像一个魅力。