使用 htaccess 重定向提交表单后 $_POST 为空 [英] $_POST empty after form submit with htaccess redirect

查看:75
本文介绍了使用 htaccess 重定向提交表单后 $_POST 为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在提交 html 表单后遇到了空 $_POST 数组的问题.

I'm experiencing a problem with an empty $_POST array after submitting a html form.

<form action="interview/booking_summary" method="POST">
    <p>Ihr Name: <input type="text" name="name" /></p>
    <p>Ihr Alter: <input type="text" name="alter" value="23" /></p>
    <p><input type="submit" name="submit" /></p>
</form>

我认为这与我的 .htaccess 文件有关.这似乎重定向页面(例如 file.php 将显示为文件(没有 .php 后缀)

I think it has to do with my .htaccess file. This seems to redirect pages (e.g. file.php will be shown as file (without .php suffix)

不幸的是,我只是在一个不是自己编程的网站上工作,所以我不太了解 htaccess 文件的作用.

Unfortunately I'm just working on a site I did not program by myself so I don't really understand what the htaccess file does.

它有一些重写规则,我认为这些规则是负责任的...

It has some ReWrite Rules and I think those are responsible...

ErrorDocument 403 /fehler/403/
ErrorDocument 404 /fehler/404/

# PHP Settings
# php_flag magic_quotes_gpc off
# php_flag register_globals off

RewriteEngine On
#Options +FollowSymlinks
RewriteBase /

# Verhindert Probleme mit Trailing Slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=301]

# Ordner
RewriteRule cronjobs\/ - [L]
RewriteRule ^([a-z]{2,2})/rss/$ /cronjobs/rss.php?language=$1 [L]

# Admincenter
RewriteRule ^admin/$ /admin/index.php [L]

# Wartung
RewriteRule ^construction/ /wartung.php [L]

# Sprache
RewriteRule ^de/$ /index.php?lang=de
RewriteRule ^en/$ /index.php?lang=en

# Allgemein

RewriteRule ^([a-z]{0,2}/)([a-zA-Z0-9_-]+)/$ /index.php?content=$2/index&lang=$1 [L]
RewriteRule ^([a-z]{0,2}/)([a-zA-Z0-9_-]+)/page-([0-9]+)/$ /index.php?content=$2/index&page=$3&lang=$1 [L]
RewriteRule ^([a-z]{0,2}/)([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ /index.php?content=$2/single&id=$3&lang=$1 [L]
RewriteRule ^([a-z]{0,2}/)([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/add-([a-zA-Z0-9_-]+)/$ /index.php?content=$2/single&id=$3&add=$4&lang=$1 [L]
RewriteRule ^([a-z]{0,2}/)([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/page-([0-9]+)/$ /index.php?content=$2/single&id=$3&page=$4&lang=$1 [L]
RewriteRule ^([a-z]{0,2}/)([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/edit-([a-zA-Z0-9_-]+)/$ /index.php?content=$2/single&id=$3&edit=$4&lang=$1 [L]
RewriteRule ^([a-z]{0,2}/)([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/delete-([a-zA-Z0-9_-]+)/$ /index.php?content=$2/single&id=$3&delete=$4&lang=$1 [L]
RewriteRule ^([a-z]{0,2}/)([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ /index.php?content=$2/single&id=$3&permalink=$4&lang=$1 [L]

# Error Dokumente
RewriteRule ^fehler/([0-9]+)/$ /index.php?content=error&code=$1 [L]

RewriteRule ^booking-summary booking-summary.php    [L]


#@__HCP_END__@#
# Anything after the comment above is left alone

我试图找到解决方案并遇到了这个线程:PHP method="post";添加此 .htaccess 后停止工作......为什么?

I tried to find a solution and came across this thread: PHP method="post" stopped working after I added this .htaccess... Why?

所以我尝试添加一个重写规则说:

And so I tried to add a rewrite rule saying:

RewriteRule ^booking-summary      booking-summary.php    [L]

但不幸的是,这并没有奏效.你能告诉我如何对这个 php 文件进行例外处理,以便我可以访问我的 $_POST 数组吗?

But unfortunately this did not do the trick. Can you tell me how I can make an exeption for this php file so that I can access my $_POST array?

提前致谢.

干杯

M

推荐答案

看看这是否有帮助.您实际上没有与您的帖子 URL 相匹配的规则.如果这是您的链接采访/booking_summary,那么它需要在规则中,因为我没有看到那里已经处理了这个问题.

See if this helps. You don't really have a rule that matches this your post URL. If this is your link interview/booking_summary, then it needs to be in the rule because I don't see one there that takes care of this already.

/ 添加到您的表单 URL,这样您就不必弄乱现有规则.

Add a / to your form URL so you don't have to go messing with existing rules.

然后试试这个重写器,提供预订摘要在面试文件夹中.

Then try this rewriterule providing booking-summary is in interview folder.

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^interview/booking-summary/?$ /interview/booking-summary.php [L]

这篇关于使用 htaccess 重定向提交表单后 $_POST 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆