Forum Moderators: phranque

Message Too Old, No Replies

newbie needs help with <filematch>

         

ycliuwz

3:00 am on Apr 21, 2005 (gmt 0)

10+ Year Member



hi there,
Could anyone advice me as to how to server only files with extensions .html .php .gif .jpg?
is it the use of

<FileMatch "\. (html¦php¦gif¦jpg)$">
Order deny,allow
allow from all
</FileMatch>

and placing this container in documentroot dir?
please advice. thanks

jdMorgan

4:01 am on Apr 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ycliuwz,

Welcome to WebmasterWorld!

That code won't work because the directive should be <FilesMatch [httpd.apache.org]> not <Filematch>.

Also, your code allows the filetypes you specified, but is not flexible enough to handle some needed exceptions.

The easiest way to do this might be to use SetEnvIf [httpd.apache.org] and Deny,Allow [httpd.apache.org]:


<Files *>
SetEnvIf Request_URI "\.(html¦php¦gif¦jpg)$" allowed_file
SetEnvIf Request_URI "^(/¦/robots\.txt)$" allowed_file
Order Deny,Allow
Deny from all
Allow from allowed_file
</Files>

I included robots.txt as an allowed file because otherwise, you may have serious problems with search engine robots. I also included "/" because this is usually a default path for your "home page."

Change the broken pipe "¦" characters above to solid pipe characters before use. Posting on this forum modifies them.

Jim

sitz

4:25 am on Apr 21, 2005 (gmt 0)

10+ Year Member



One small addition; if you think you might be dealing with cases in which the filesnames are in upper- or mixed- case (such as 'INDEX.HTML'), you can use the SetEnvIfNoCase [httpd.apache.org] directive instead of SetEnvIf [httpd.apache.org].

ycliuwz

7:24 am on Apr 21, 2005 (gmt 0)

10+ Year Member



hi jp morgan,
Thanks for the help.
I;ve tried putting as instructed in place but when i restarted my server...i couldn't access any of the pages.
i keep getting forbidden.

the goal was to server only html php gif and jpg file extensions..could you please advice again.thanks

ycliuwz

1:28 am on Apr 22, 2005 (gmt 0)

10+ Year Member



1. how can i configure apache to serve only file extensions html php gif jpg

<FilesMatch "\.(html¦php¦gif¦jpg)$">
Order deny,allow
allow from all
</FilesMatch>
is it done this way? it doesn't seem to work.

2.how to configure virtual host to disallow serving of directory content?

3. Virtual host logs.
how can i record its access logs to a seperate file?
with ip address and in common log format?

please advice. thanks

ycliuwz

6:24 am on Apr 22, 2005 (gmt 0)

10+ Year Member



1. how can i configure apache to serve only file extensions html php gif jpg
<FilesMatch "\.(html¦php¦gif¦jpg)$">
Order deny,allow
allow from all
</FilesMatch>
is it done this way? it doesn't seem to work.

2.how to configure virtual host to disallow serving of directory content?

3. Virtual host logs.
how can i record its access logs to a seperate file?
with ip address and in common log format?

please advice. thanks