简体   繁体   English

具有POST数据的多个URL重定向htaccess

[英]multiple URL redirect htaccess with POST data

In my project for REST API older version I have multiple setups. 在我的REST API旧版本项目中,我有多种设置。 In newer version I have the common setup code instead of multiple setups. 在较新的版本中,我有通用的设置代码,而不是多个设置。

I have to write htaccess rule to redirect old URL's into new version URL. 我必须编写htaccess规则将旧URL重定向到新版本URL。 All the requests are POST request so I have to redirect without affecting the POST data. 所有请求都是POST请求,因此我必须重定向而不影响POST数据。

Problem 问题

Old Setup URL 旧设定网址

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/client1/a_report/index.php/rest_server/index http://example.com/client2/a_report/index.php/rest_server/index

I want these URL's need to be redirected to the latest one 我希望这些网址需要重定向到最新的网址

http://example.com/commonsetup/index.php/rest_server/index http://example.com/commonsetup/index.php/rest_server/index

I tried this following code it is not working as expected 我尝试了以下代码,但无法正常工作

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]

This code is working but it's giving the Wrong URL. 这段代码有效,但是给出了错误的URL。 In this case the POST will becomes GET. 在这种情况下,POST将变为GET。 This also I need to fix 这我也需要修复

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/client1/
RewriteRule (.*) /commonsetup/$1 [R=301,L]

The result I got in the browser 我在浏览器中得到的结果

Not Found The requested URL /commonsetup/client1/a_report/index.php/rest_server/index was not found on this server. 找不到在此服务器上找不到请求的URL /commonsetup/client1/a_report/index.php/rest_server/index。

The required output is 所需的输出是

/commonsetup/index.php/rest_server/index /commonsetup/index.php/rest_server/index

Please help me to achieve this. 请帮助我实现这一目标。 Thanks in advance. 提前致谢。

As I commented above POST data will be lost if doing an external redirect. 正如我上面评论的那样,如果进行外部重定向,则POST数据将丢失。

You have 3 options to preserve POST data: 您有3个保留POST数据的选项:

  1. Don't do redirect and do an internal rewrite only 不要重定向,而只做内部重写
  2. Enable mod_proxy and use P flag for proxying the request 启用mod_proxy并使用P标志代理请求
  3. Write server side code eg using curl and pass-on POST data to destination 编写服务器端代码,例如使用curl和传递的POST数据到目标

Try this rule for internal rewrite in your DOCUMENT_ROOT/.htaccess file: 尝试使用以下规则在DOCUMENT_ROOT/.htaccess文件中进行内部重写

RewriteEngine On

RewriteRule ^(?:client2|client1)/a_report/(.+)$ /commonsetup/$1 [NC,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM