stop direct access (.htaccess) and allow ajax request to subfolder

后端 未结 5 783
情书的邮戳
情书的邮戳 2020-12-20 01:42

I am trying to stop direct access to a subdirectories and the php files within subdirectories. I\'ve added the following code below to the .htaccess file within the subdirec

5条回答
  •  执笔经年
    2020-12-20 02:43

    Put this code in your DOCUMENT_ROOT/.htaccess file:

    RewriteEngine On
    
    ## disable direct access (but allow internal or AJAX requests)
    RewriteCond %{HTTP_REFERER} !^$ 
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain\.com/ [NC] 
    RewriteRule ^subdir(/|$) - [F,NC]
    

    Replace www.domain.com by your own domain name.

    Note that this uses %{HTTP_REFERER} header to do this blocking and it is possible to manipulate this header value.

提交回复
热议问题