更改.htaccess后未发布的数据

时间:2013-08-14 04:14:37

标签: php html .htaccess

我正在使用PHP创建一个网站,一切正常,但是当我更改.htaccess文件后,表单方法不会发布数据。

  

.htaccess文件(我在stackoverflow.com上找到了这个)

#Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## don't touch /forum URIs
RewriteRule ^forums/ - [L,NC]

## hide .php extension snippet

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

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
  

形式

 <form method="post" id="form" action="view_images.php">
    <input type="text" name="img" value="images/1.jpg" id="img_name" />
    <input type="submit" id="submit" value="submit" />
</form>

任何想法有什么不对?

1 个答案:

答案 0 :(得分:0)

这条规则:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]

导致您对view_images.php的POST请求被重定向到view_images,从而丢失了请求正文(所有POSTed数据)。您不希望导致此重定向,因此请勿POST到view_images.php URL。删除.php部分,使其不会重定向:

<form method="post" id="form" action="view_images">
    <input type="text" name="img" value="images/1.jpg" id="img_name" />
    <input type="submit" id="submit" value="submit" />
</form>