PHP Rewrite url and preserve posted data
I have a php server and i want to rewrite incoming urls. Since incoming requests are post requests I also want posted data to be transferred at the new urls.
I have managed to redirect urls with the following rewrite rules:
RewriteRule ^test/(.*)$ http: //localhost/index.php?data=&1 [NC,L]
or
RewriteRule ^test/(.*)$ http: //localhost/index.php?data=&1 [NC,R=301]
I have also managed to preserve post data with the following rewrite rule:
RewriteRule ^test/(.*)$ http: //localhost/index.php?data=&1 [P]
开发者_JAVA技巧The problem is that I can not both of them at the same time. What am I doing wrong? Is there a way to redirect url and keep post data?
Your issue probably is that you do redirects instead of rewrites. Redirects change the URL people see in the browser. Rewrites only change the URL that your PHP app sees. The latter is normally what you want. And in the latter case POST variables are automatically preserved.
In order to rewrite instead of redirect, use a local path instead of a URL:
RewriteRule ^test/(.)$ index.php?data=$1 [NC,L]
精彩评论