htaccess和AJAX POST值

I am new to htaccess and I am having trouble with POST values through AJAX.

Everything worked before I started playing with htaccess so it is probably a simple fix.

My post values are being lost through AJAX and I think it is because I have rewritten the urls to remove the suffix (php) using htaccess. I had some trouble with POST values on the normal scripts (ie login) which was solved by adding a rewrite condition.

Please see below my code:

# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php  
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^index.php / [L,R=301]

The problem is your R tag. This causes a redirect. Unfortunately early web browsers didn't follow the HTTP specifications and used GET to request the new URL they were given. THis has led to HTTP being changed (e.g. the 308 code introduced).

Basically, you can't reliably issue an external redirect for anything other than a GET request. Use internal redirects (re-writes) instead. i.e, leave off the R tag from the end of your first RewriteRule.