【问题标题】:data not posting after changing the .htaccess更改 .htaccess 后数据未发布
【发布时间】:2013-08-14 04:14:36
【问题描述】:

我正在用 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>

有什么想法吗?

【问题讨论】:

  • 你知道文件“view_images.php”是否解析吗?我的意思是,尝试在浏览器中直接访问“view_images.php”。也许添加一个调试字符串并将其回显。我的猜测是您的 RewriteRule 之一已损坏并阻止加载 view_images.php。
  • view_images.php 正在加载,但变量 $_POST['img'] 显示为空。

标签: php html .htaccess


【解决方案1】:

这条规则:

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

导致您对 view_images.php 的 POST 请求被重定向到 view_images,因此您丢失了请求正文(所有已发布的数据)。你不想引起这个重定向,所以不要发布到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>

【讨论】:

    猜你喜欢
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多