很抱歉,我無法獨自解決這個問題...成功付款後,用戶將被重定向到我網站上的此 URL:
https://www.example.com/orders/?token=AAA&status=OK
我想獲取令牌和狀態並將它們分配給 GET 變量,但我真的無法這樣做,這是我當前的 RewriteRule:
RewriteRule ^orders/?token=([^/]+)&status=([^/]+)$ /orders.php?lang=it&token=$1&result=$2 [L]
在orders.php
我有這一行:
echo "token: ".$_GET['token'];
但當然在控制台我總是得到
PHP Notice: Undefined index: token in /orders.php on line 3
有人可以幫我嗎?
您無法使用RewriteRule
pattern匹配查詢字符串,您需要使用RewriteCond
指令並檢查QUERY_STRING
服務器變量。但是,在這種情況下,您還必須確保MultiViews
禁用(否則orders.php
將在沒有任何 URL 參數的情況下調用)。
請嘗試以下操作:
# MultiViews MUST be disabled
Options -MultiViews
# Rewrite URL with query string
RewriteCond %{QUERY_STRING} ^token=([^&]+)&status=([^/]+)$
RewriteRule ^orders/$ orders.php?lang=it&token=%1&result=%2 [L]
注意,這裡使用的%1
和%2
反向引用(相對於$1
和$2
該獲得從捕獲的組的值在前面的)條件,而不是在RewriteRule
圖案。
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다