marchemike
marchemike

Reputation: 3277

Prevent htaccess from affecting ajax requests

I'm trying to modify my htaccess request, it currently loads all the files that are php, but removes the .php extension. However I noticed that this affects my ajax requests, as I cannot get any POST data from them. What do I add to my htaccess to prevent a specific php(data.php) from not being affected by the extension removal of the htaccess?

The code of my htaccess:

RewriteEngine On

# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]

Upvotes: 4

Views: 2629

Answers (2)

anubhava
anubhava

Reputation: 785196

You can use:

RewriteEngine On

# skip POST requests
RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^ - [L]

# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]

Upvotes: 1

Rakesh Sharma
Rakesh Sharma

Reputation: 13728

may be you sending some data on post then check in htaccess if url with data then ignore rewrite or use post url in ajax without php extension like url/data

 url: data, //instaed of data.php

Upvotes: 2

Related Questions