原文地址:https : //www.example.com/all_users/user.php?id=1&subtype=p
預期網址:https : //www.example.com/user/john-doe.html
我嘗試使用以下規則,它重定向到預期的 URL,但我不能使用帶有新 URL 的引數(id 和子型別)。
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id\=1&subtype\=p$
RewriteRule ^all_users/user\.php$ https://www.example.com/user/john-doe.html? [R=301,L]
如何在新 URL 中使用引數值。
例子:
重定向后,新 URL 將是https://www.example.com/user/john-doe.html 然后我應該能夠使用新 URL 獲取原始引數值。
$id = $_GET['id'];
$type = $_GET['subtype'];
uj5u.com熱心網友回復:
使用您顯示的示例和嘗試,請嘗試遵循 htaccess 規則。
在測驗您的 URL 之前,請確保清除瀏覽器快取。
RewriteEngine ON
##External redirect here.
RewriteCond %{THE_REQUEST} \s/all_users/user\.php\?id=\d &subtype=p\s [NC]
RewriteRule ^ user/john-doe.html? [R=301,L]
##Internal rewrite from here..
RewriteRule ^user/john-doe\.html/?$ all_users/user.php?id=1&subtype=p [QSA,NC,L]
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/393718.html
