sábado, 14 de junho de 2008

Usar Apache para restringir acesso a arquivos

Using Apache to restrict file access

PORTUGUÊS

O Apache fornece um módulo especial de segurança que é definido através do arquivo .htaccess. Este é o nome padrão do arquivo que contém as diretivas que definirão o comportamento do servidor Apache. Este arquivo é acessado toda vez que um usuário faz uma requisição ao servidor, o servidor então procura pelo arquivo .htaccess e verifica as permissões ou negações definidas no arquivo.

Este arquivo pode ser usado para fazer restrições de acesso a arquivos, com senha ou não. O código abaixo restringe o acesso aos arquivos do site somente ao domínio http://www.genomaweb.net/, ou seja, qualquer site que tentar linkar algum arquivo do site http://www.genomaweb.net/, como imagens, javascript e folhas de estilo, não vai conseguir.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://www.genomaweb.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.genomaweb.net$ [NC]
RewriteRule .*\.(.*)$ http://www.genomaweb.net/ [R,NC]

INGLÊS

Apache has a special security module that is defined by the file .htaccess. This is the default name of the file that contain the directives that will define the behavior of the Apache server. This file is accessed every time that an user make a requisition to the server, then the server search for the file .htaccess and check the permissions and prohibitions defined in the file.

This file can be used to make access restrictions to files, with password or not. The code below restrict the access to the files of website just fot the domain http://www.genomaweb.net/, it's mean, any website that try to link some file of http://www.genomaweb.net/, like imagens, javascript and cascade style sheets, won't get it.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://www.genomaweb.net/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.genomaweb.net$ [NC]
RewriteRule .*\.(.*)$ http://www.genomaweb.net/ [R,NC]