开发者

PHP won't receive POST requests at /directory/ only at /directory/index.php

When POST request are sent to "http://domain.com/directory/", the POST data isn't received. But if it's sent to "http://domain.com/directory/index.php" it is received.

How can I make it work when just th开发者_运维技巧e directory is called? Thanks!


If you're running Apache, check if the mod_dir module is enabled and configured correctly. These are the contents of my dir.conf:

<IfModule mod_dir.c>
    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>


Have you tried using a tool like HttpFox for Firefox to see if when you make a request to the directory on its own, you are being redirected? I know a redirect can kill a POST request as it gets converted into a GET request.


As Lucanos said, is the web server redirecting to index.php? POST data might get "lost" between pages if you redirect. Try GET and check if the URL ends with correct data.


Create ".htaccess" file inside /directory/ with this content

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

It tells server to route all request that are physically not possible (since no file or folder exist for that request) to index.php , advantage of this is that your .css file .js , .jpg files wont get routed to index.php .


If the directory contains index.html alongwith index.php, just rename the index.html file else delete the file because if you give the path to directory only, the index.html always gets enabled no matter the index.php still exists in the same directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜