Options All -Indexes
Options +FollowSymlinks
RewriteEngine on

# on laisse l'accès normal :
#  - si le fichier n'existe pas
#  - ou si on trouve un REFERER correspondant au HOST
#  - ou si on trouve un REFERER correspondant au X-Forwarded-Server dans le cas d'un reverse proxy
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{HTTP_REFERER}::%{HTTP_HOST} ^https?://([^/]+)/cdt/.+::\1$ [NC,OR]
RewriteCond %{HTTP_REFERER}::%{HTTP:X-Forwarded-Server}  ^https?://([^/]+)/cdt/.+::\1$ [NC]

# le drapeau "S=1" signifie que l'on saute la règle suivante (redirection vers le message d'erreur) quand une des conditions est remplie
RewriteRule .? - [S=1]

RewriteRule .* /cdt/erreur403.html [L,R=302]
