Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

php - Redirect 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...