加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 重定向POST htaccess

发布时间:2020-12-13 18:20:35 所属栏目:PHP教程 来源:网络整理
导读:这个问题非常类似于: Is it possible to redirect post data?(问问听者),但这个答案对我来说似乎不起作用. 我有一个表格: form action="http://a.test.com/contact" name="contact" method="post" 在一个附加域内,(test.com是一个插件),有一个子域(a.),里
这个问题非常类似于: Is it possible to redirect post data?(问问听者),但这个答案对我来说似乎不起作用.

我有一个表格:

<form action="http://a.test.com/contact" name="contact" method="post">

在一个附加域内,(test.com是一个插件),有一个子域(a.),里面有一个文件item.php和.htaccess

我的htaccess如下:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)/$$1.php 

# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$/$1/ [R=301,L]

#normal rewrites
RewriteRule ^[~|-]?([a-zA-Z0-9]+)[/]*$item.php?user=$1 [NC,L]

注意:我将其保留为[NC,L],因为当我将其更改为[NC,P]时,它给出了500服务器错误.

和我的item.php

<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";

并且无论表单包含什么,$_POST都是空白的……但是,如果我将http://a.test.com/item.php?user=contact作为动作.

一切顺利. POST跳过了htaccess,SO上的解决方案似乎不起作用.

提前致谢

您的“添加尾随斜杠”规则会强制执行标头重定向:
[R=301,L]

标头重定向将丢弃POST值.

您必须删除该规则,或者为POST提交禁用它:

# Forces a trailing slash to be added

RewriteCond %{REQUEST_METHOD}  !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,L]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读