表单没有';t在操作url的末尾不带反斜杠


Form doesn't post without backslash at the end of action url

今天我遇到了这个奇怪的问题,它让我大吃一惊,因为我不知道为什么会发生这种情况,我有一个带有这个动作http://localhost/wp/的表单,但如果没有末尾的反斜杠,它就不起作用,我的意思是,当动作是http://localhost/wp时,它不起作用,让我给你举个例子:

<form action="<?php bloginfo("url"); ?>" method="post">
       <input type="text" name="example">
</form>
<?php
      var_dump( $_POST ); // will output an empty array
?>

但现在我们在动作结束url中添加了一个"/",它可以工作,但我希望它能双向工作,因为我是为客户设计这个网站的。

<form action="<?php bloginfo("url"); ?>/" method="post">
       <input type="text" name="example">
</form>
<?php
      var_dump( $_POST ); // will output array( "example" => "XXXX" )
?>

有人能告诉我怎么了吗!!

::它是安装在XAMPP-Windows 8.1 上的wordpress

使用`http://localhost/wp/,这将执行目录/path/to/localhost/wp/中的任何Apache默认文件。例如在WordPress案例index.php.

当您使用http://localhost/wp时,它告诉Apache执行目录/path/to/localhost/中的文件wp。

因此,这两个案例要求两种不同的东西,结果不同。

如果你总是想运行WordPress,那么修改你的.htaccess文件,使其始终转到localhost/wp/,即使用户没有添加斜杠。