我正在建立一個網站(在 Joomla 4 中,如果相關的話),我正在嘗試使用 .htaccess 來重定向 URL,如下所示:
index.php/characters
...到這樣的 URL:
index.php/characters?reset=true
...但不要理會這樣的 URL:
index.php/characters?search=fred
我使用https://htaccess.madewithlove.com/來測驗以下規則,并且模擬看起來完全可以達到我想要的效果:
RewriteCond %{QUERY_STRING} ^(?!search)
RewriteRule index.php/characters /index.php/characters?reset=true [L,R,QSA]
但這給了我無盡的重定向,看起來像這樣:
index.php/characters?reset=true&reset=true&reset=true&reset=true&reset=true&reset=true&reset=true&reset=true (etc)
我在這里做錯了什么?
uj5u.com熱心網友回復:
您可以使用這樣的重定向規則:
RewriteCond %{QUERY_STRING} !(^|&)(search|reset)= [NC]
RewriteRule ^index\.php/characters/?$ /$0?reset=true [L,R,QSA]
RewriteCond %{QUERY_STRING} !(^|&)(search|reset)= 如果查詢字串具有以search=or開頭的引數,否定條件將跳過該規則reset=。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/431730.html
標籤:.htaccess
