科技知識動態:偽靜態規則中RewriteCond如何獲取多個參數?

導讀跟大家講解下有關偽靜態規則中RewriteCond如何獲取多個參數?,相信小伙伴們對這個話題應該也很關注吧,現在就為小伙伴們說說偽靜態規則中R

跟大家講解下有關偽靜態規則中RewriteCond如何獲取多個參數?,相信小伙伴們對這個話題應該也很關注吧,現在就為小伙伴們說說偽靜態規則中RewriteCond如何獲取多個參數?,小編也收集到了有關偽靜態規則中RewriteCond如何獲取多個參數?的相關資料,希望大家看到了會喜歡。

現有如下表單規則:/index.php?m=search&c=index&s=1&t=1&k=關鍵詞想通過偽靜態的形式將路徑轉發為/search?s=1&t=1&k=關鍵詞

使用如下方式只能獲取一個參數值RewriteCond %{QUERY_STRING} ^k=(.+)$RewriteRule ^search$ /index.php?m=search&c=index...&k=%1

使用如下方式獲取多個參數的話參數的順序是固定的,一旦調換順序就不行了RewriteCond %{QUERY_STRING} ^k=(.+)&s=(.+)&c=(.+)$RewriteRule ^search$ /index.php?m=search&c=index...&k=%1&s=%2&c=%3

使用如下方式的話,有安全隱患,不能限定參數的個數RewriteRule ^search$ /index.php?m=search&c=index [L,QSA]

請教大神們有什么好的解決方案?

回復內容:

現有如下表單規則:/index.php?m=search&c=index&s=1&t=1&k=關鍵詞想通過偽靜態的形式將路徑轉發為/search?s=1&t=1&k=關鍵詞

使用如下方式只能獲取一個參數值RewriteCond %{QUERY_STRING} ^k=(.+)$RewriteRule ^search$ /index.php?m=search&c=index...&k=%1

使用如下方式獲取多個參數的話參數的順序是固定的,一旦調換順序就不行了RewriteCond %{QUERY_STRING} ^k=(.+)&s=(.+)&c=(.+)$RewriteRule ^search$ /index.php?m=search&c=index...&k=%1&s=%2&c=%3

使用如下方式的話,有安全隱患,不能限定參數的個數RewriteRule ^search$ /index.php?m=search&c=index [L,QSA]

請教大神們有什么好的解決方案?

把 k s c 等參數仍然作為正則匹配,如:

RewriteCond %{QUERY_STRING} ^([a-z]+)=(.+)&([a-z]+)=(.+)&([a-z]+)=(.+)$RewriteRule ^search$ /index.php?m=search&c=index...&%1=%2&%3=%4&%5=%6

來源:php中文網

免責聲明:本文由用戶上傳,如有侵權請聯系刪除!