允许 PHP $_POST 与 htaccess

发布于 2024-09-30 03:44:11 字数 1184 浏览 1 评论 0原文

我对 htaccess 不太擅长,但对迄今为止所做的事情感到满意,直到我注意到我的 $_post 变量没有被处理,因为我的 htaccess 文件中的重写签名(SIGH)

我的目标是读取 url 并确定它是来自 php 的路径和位置,它是 $_SERVER['request_uri'] 方法,工作正常。 http://mydomain.com/ 之后的所有内容都会被分解并用作数据,因此需要 htaccess。

我的htaccess:

AddType text/x-component .htc

Options +FollowSymlinks

<Files .htaccess>
 order allow,deny
 deny from all
</Files>

IndexIgnore *

ErrorDocument 404 /index.php?/

<FilesMatch "(\.jpe?g|gif|png|bmp)$">
  ErrorDocument 404 "File Not Found"
</FilesMatch>

RewriteEngine On

RewriteBase /
RewriteRule (.*)\.htm $1.php [L,NC]

我的php:(记住所有内容都是通过index.php解析的)

php与问题无关,因为我知道它应该有效。我一直在使用 print_r($_POST) 测试 post 变量,从表单提交时它们是空的。明显的问题是我对 htaccess 缺乏了解。

就为了这个话题。假设我的index.php 看起来像这样:

<?php

print_r($_POST);

?>

<form action="" method="post">
  <input type="text" name="test">
  <input type="submit" value="Test!">
</form>

这里的在线示例: www.blueaspect.com <-- 表格有效!

然后通过将 foo/ 添加到 url 末尾,您将看到加载的文件仍然是 index.php。这就是我想要的,但现在该表格不起作用。

如果有人可以提供帮助,我们将不胜感激

I'm not so good on htaccess but was happy with what I had done so far until I noticed my $_post variables were not being processed because of the rewrite signiture within my htaccess file (SIGH)

My objective was to read the url and determine it's path and location from php and it's $_SERVER['request_uri'] method, which works fine. Everything after http://mydomain.com/ gets ripped apart and used as data hence the need for htaccess.

my htaccess:

AddType text/x-component .htc

Options +FollowSymlinks

<Files .htaccess>
 order allow,deny
 deny from all
</Files>

IndexIgnore *

ErrorDocument 404 /index.php?/

<FilesMatch "(\.jpe?g|gif|png|bmp)$">
  ErrorDocument 404 "File Not Found"
</FilesMatch>

RewriteEngine On

RewriteBase /
RewriteRule (.*)\.htm $1.php [L,NC]

my php: (baring in mind everything gets parsed through index.php)

The php is irrelevant to the problem as I know it should work. I have been testing the post variables by using print_r($_POST) and they are empty when submitted from a form. The obvious problem is down to my lack of knowledge with htaccess.

Just for this thread. lets say my index.php looked like this:

<?php

print_r($_POST);

?>

<form action="" method="post">
  <input type="text" name="test">
  <input type="submit" value="Test!">
</form>

online example here:
www.blueaspect.com <-- The form works!

Then by adding foo/ to the end of the url you'll see the file loaded is still index.php. Which is what I want but now the form does not work.

Please if anyone could help that would be much appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晚雾 2024-10-07 03:44:12
AddType text/x-component .htc

RewriteEngine On
RewriteBase /
RewriteRule (.*)?\.(sb|html|htm|php|asp|aspx)$ index.php

解决了这个问题

AddType text/x-component .htc

RewriteEngine On
RewriteBase /
RewriteRule (.*)?\.(sb|html|htm|php|asp|aspx)$ index.php

fixed that problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文