簡體   English   中英

具有POST數據的多個URL重定向htaccess

[英]multiple URL redirect htaccess with POST data

在我的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數據將丟失。

您有3個保留POST數據的選項:

  1. 不要重定向,而只做內部重寫
  2. 啟用mod_proxy並使用P標志代理請求
  3. 編寫服務器端代碼,例如使用curl和傳遞的POST數據到目標

嘗試使用以下規則在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