PHP重写URL和preserve发布的数据 [英] PHP Rewrite url and preserve posted data

查看:115
本文介绍了PHP重写URL和preserve发布的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP的服务器,我想重写传入的URL。由于传入的请求是POST请求,我也想发布的数据,以在新的URL进行传输。

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]

RewriteRule ^test/(.*)$ http: //localhost/index.php?data=&1 [NC,R=301]

我也设法preserve后的数据具有以下重写规则:

I have also managed to preserve post data with the following rewrite rule:

RewriteRule ^test/(.*)$ http: //localhost/index.php?data=&1 [P]

问题是,我不能两个人都在同一时间。我究竟做错了什么?有没有一种方法来重定向URL,并保持后的数据?

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?

推荐答案

您的问题可能是你做的重定向而不是重写。重定向改变人们在浏览器中看到的网址。重写只能改变你的PHP应用程序看到的URL。后者通常是你想要的。而在后一种情况下,POST变量是自动preserved

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.

为了改写,而不是重定向,使用,而不是一个URL的本地路径:

In order to rewrite instead of redirect, use a local path instead of a URL:

RewriteRule ^test/(.)$ index.php?data=$1 [NC,L]

这篇关于PHP重写URL和preserve发布的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆