I have a folder named chatlogs on my root (path: root/chatlogs) and a .htaccess file in chatlogs folder that Denies any request from url to the contents of chatlogs. Now i wanna allow ajax calls to this folder. (Imagine some files named : log0.html , log1.html , ... in chatlogs folder)
htaccess:
Deny from all
my ajax call:
function loadLog(){
$.ajax( {
url: "chatlogs/log0.html",
cache: false,
success: function( html ){
$(" #chatbox ").html( html ); //Insert chat log into the #chatbox div
}
},
});
setInterval ( loadLog, 1500 );
Apparently the loadlog() function has no access to chatlogs folder. How can i allow this ajax call to enter in chatlogs folder? Should i add some lines in .htaccess file ??? Thanks in advance
edit your .htaccess:
SetEnvIfNoCase X-Requested-With XMLHttpRequest ajax
Order Deny,Allow
Deny from all
Allow from env=ajax
... SetEnvIfNoCase - allow you to conditionally set environment variables accessible by scripts and apache based on the value of HTTP Headers, Other Variables, and Request information. In our case: if there's header "X-Requested-With" the environmental variable "ajax" will be set. Allow from env=ajax (allows access only for requests with above headers)