urls 中有一個動態引數s=changingtext。有必要識別這個引數并在其中添加另一個引數以重定向到 get s=changingtext&post_type=product。
有一個鏈接,例如
example.com/?min_price=0&max_price=0&s=test
它應該總是重定向到
example.com/?min_price=0&max_price=0&s=test&post_type=product
uj5u.com熱心網友回復:
提供 URL 引數的順序并不重要,那么您可以使用.htaccess檔案頂部的 mod_rewrite 這樣做:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)s=[^&]
RewriteRule ^ %{REQUEST_URI}?post_type=product [QSA,R=302,L]
這首先添加post_typeURL 引數,并使用QSA(Query String Append) 標志附加現有的查詢字串。IE。在您的示例中,它將被重定向到example.com/?post_type=product&min_price=0&max_price=0&s=test.
這會專門檢查非空sURL 引數。一個空的 URL 引數,例如。foo=1&s=&bar=1不會被重定向。
這適用于任何 URL 路徑。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/372982.html
