2011-01-09 62 views
7

這個問題非常類似於:Is it possible to redirect post data?(被問到的問題),但是這個答案似乎不適用於我。重定向POST htaccess

我有一個表格:

<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作爲動作。

一切順利。發佈時跳過htaccess,而SO上的解決方案似乎不起作用。

在此先感謝

+1

爲什麼你** **重定向客戶端呢?如果您不想重定向,請刪除重定向規則(或僅刪除重定向標誌),從而丟失POST數據。 – zerkms 2011-01-09 10:29:38

+0

可能重複的[.htaccess - 是否有可能重定向發佈數據?](http://stackoverflow.com/questions/358263/htaccess-is-it-possible-to-redirect-post-data) – 2013-03-15 12:11:21

回答

17

「加入斜線」規則強制重定向頭:

[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,5}|/)$ 
RewriteRule (.*)$ /$1/ [R=301,L]