Skip to content

Instantly share code, notes, and snippets.

@mocanuga
Created September 29, 2016 15:56
Show Gist options
  • Save mocanuga/6ba525ee9f6aaed6d11cac8d2e2cae82 to your computer and use it in GitHub Desktop.
Save mocanuga/6ba525ee9f6aaed6d11cac8d2e2cae82 to your computer and use it in GitHub Desktop.
Ajax request detection in htaccess
ErrorDocument 404 NotFound
ServerSignature Off
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_METHOD} ^(GET)$
RewriteCond %{HTTP:X-Requested-With} XMLHttpRequest [NC] # i had to add no case to work
RewriteRule ^(.*)$ script.php?url=$1&get=true [NC,L,QSA]
RewriteCond %{REQUEST_METHOD} ^(POST)$
RewriteCond %{HTTP:X-Requested-With} XMLHttpRequest [NC]
RewriteRule ^(.*)$ script2.php?url=$1&post=true [NC,L,QSA]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment