偽靜態規則中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
等參數仍作為正規匹配,如:
<code>RewriteCond %{QUERY_STRING} ^([a-z]+)=(.+)&([a-z]+)=(.+)&([a-z]+)=(.+)$ RewriteRule ^search$ /index.php?m=search&c=index...&%1=%2&%3=%4&%5=%6</code>

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

適用於 Ubuntu 和 Debian 的 PHP 8.4 安裝和升級指南

如何設定 Visual Studio Code (VS Code) 進行 PHP 開發
