I recently had a Joomla site hacked, so I'm trying to harden the site a bit. There's a section in the recommended .htaccess that restricts outside access to the xml files that come with extensions. However, it also keeps my sitemap.xml file from being accessed.

How do I allow a certain file whiles keeping the rest?

here's the default code:

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

and my modification that caused a 500 error:

<Files ~ "(?!sitemap)\.xml$">
 Order allow,deny
 Deny from all
 Satisfy all
</Files>
link|improve this question
Care to specify what the error message is? You'll find it in your error_log. – tylerl Jul 31 '10 at 8:02
feedback

3 Answers

up vote 0 down vote accepted

The FilesMatch line has an extra "<". It should be:

<FilesMatch "(?!sitemap)\.xml$">
link|improve this answer
feedback

You should use <FilesMatch> as documented here

Also, I think your regex should be (?<!sitemap)\.xml$ instead. Like this:

<FilesMatch "(?<!sitemap)\.xml$">
   Order allow,deny
   Deny from all
</FilesMatch>
link|improve this answer
Still cased a 500 error for me. – CEich Jul 31 '10 at 7:09
feedback

I finally decided not to mess with the regex.

I added:

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

afterward and it works like a charm.

link|improve this answer
Don't you mane "Deny from all" on line 3? – Peter Ajtai Aug 1 '10 at 21:25
no, putting this under the directive to deny all .xml files overrides the directive in this one case. Thus, though not as cool looking as the regex solution, it still works. – CEich Aug 3 '10 at 15:03
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.