Ajax调用正被.htaccess文件重定向到其他页面

What I am doing is whenever someone hits "subdomain.example.com" I show the content of "http://example.com/file1.php" page which I am handling by ".htaccess" file. But I am facing issues while making an ajax request. I have some logics written on the page "functions.php". Now whenever I make an ajax call to "subdomain.example.com/functions.php" it returns me the whole HTML content of the page "http://example.com/file1.php".

Below is the code I have written in .htaccess file

RewriteEngine On
#RewriteBase /

RewriteCond %{HTTP_HOST} =subdomain.example.com
RewriteRule (.*) http://example.com/file1.php [P]

I am trying to handle it by .htaccess but could not reach to the solution. Can somebody explain me how I can handle the ajax request so I can get the JSON data from functions.php page.

My code which I tried but didnt work:

RewriteEngine On
#RewriteBase /

RewriteCond %{HTTP_HOST} =subdomain.example.com/$1
RewriteRule (.*)file1.php http://example.com/$1 [P]

htaccess always gives me a headache and I am by no means an expert, but I believe that you want to add a couple of lines to exclude existing files or directories from your rewrite rule with the following:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

I hope that does it for you!

I found the solution for this, Now I am just skipping POST methods which I am getting from AJAX calls,

RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^ - [P]

this is working fine for me.