[英]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數據的選項:
mod_proxy
並使用P
標志代理請求 curl
和傳遞的POST數據到目標 嘗試使用以下規則在DOCUMENT_ROOT/.htaccess
文件中進行內部重寫 :
RewriteEngine On
RewriteRule ^(?:client2|client1)/a_report/(.+)$ /commonsetup/$1 [NC,L]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.