【发布时间】:2014-02-05 05:53:40
【问题描述】:
在我的 REST API 旧版本项目中,我有多个设置。在较新的版本中,我有通用设置代码而不是多个设置。
我必须编写 htaccess 规则来将旧 URL 重定向到新版本 URL。所有请求都是 POST 请求,所以我必须在不影响 POST 数据的情况下进行重定向。
问题
旧设置网址
http://example.com/client1/a_report/index.php/rest_server/index http://example.com/client2/a_report/index.php/rest_server/index
我希望将这些网址重定向到最新的网址
http://example.com/commonsetup/index.php/rest_server/index
我尝试了以下代码,但没有按预期工作
RewriteEngine On
RewriteBase /
RewriteRule ^client1/a_report(.*) http://example.com/commonsetup/$1 [NC,L,P]
RewriteRule ^client2/a_report(.*) http://example.com/commonsetup/$1 [NC,L,P]
此代码有效,但给出的 URL 错误。在这种情况下,POST 将变为 GET。这也是我需要解决的
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/client1/
RewriteRule (.*) /commonsetup/$1 [R=301,L]
我在浏览器中得到的结果
未找到请求的 URL /commonsetup/client1/a_report/index.php/rest_server/index 不是 在此服务器上找到。
需要的输出是
/commonsetup/index.php/rest_server/index
请帮助我实现这一目标。提前致谢。
【问题讨论】:
-
POST 数据在重定向后不会传输。通过服务器端的 curl 来完成。
-
我有 50 个设置,我必须摆脱这个,这就是为什么那个地方的公共代码。好的如何重定向
-
只要您的重写规则实际上并未重定向页面(而只是在内部重写路径),您的 POST 数据就会被保留,因为它仍在使用相同的 HTTP 请求。 - 从谷歌收集