dongxin0031 2011-01-09 10:24
浏览 7
已采纳

重定向POST htaccess

This question is very similar to: Is it possible to redirect post data? (asked eariler) but that answer does not seem to work for me.

I have a form:

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

and inside of a add-on domain, (test.com is an addon), there is a subdomain (a.), and inside of there I have a file item.php, and .htaccess

my htaccess is as follows:

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]

note: I left it as [NC,L] because when I changed it to [NC,P] it gives me a 500 server error.

and my item.php

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

and no matter what the form contains, the $_POST is blank... however, if I do http://a.test.com/item.php?user=contact as the action.

all goes well. POSTing skips the htaccess, and the solution on SO doesn't seem to work.

Thanks in advance

  • 写回答

1条回答 默认 最新

  • doqp87012 2011-01-09 10:30
    关注

    Your "add trailing slash" rule forces a header redirect:

     [R=301,L]
    

    a header redirect will drop POST values.

    You will have to drop that rule, or disable it for POST submissions:

    # 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]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗