首頁  >  問答  >  主體

apache - url 位址重寫 如何去區分 ‘? ’ 問號

網址:http://localhost/aaa/bbb-ccc=222

RewriteRule ^([a-z,\/,_,0-9]*)-(.*)$ index.php?routeeee=$1&$2 [L]

當用 ‘-’ 去區分位址URL時 資料都可以取得到,’-‘相當於一個分隔符號

Array ( [routeeee] => aaa/bbb [ccc] =>222 )

當url位址中的‘-‘ 換成’? ‘ 時就無法取得數據 RewriteRule ^([a-z,\/,_,0-9]*)?(.*)$ index.php?routeeee=$1&$2 [L] http://localhost/aaa/bbb?ccc=222

Array ( [routeeee] => index [_php] => )

RewriteRule ^([a-z,\/,_,0-9]*)?(.*)$ index.php?routeeee=$1&$2 [L] 這條規則該如何寫 才能正常匹配 取得到正確的資料。

\? 轉義 ‘? ’問號的話 就不符了

不勝感激

但是在nginx中這樣是可以使用的

rewrite ^/(.)?(.)$ /index.php?route=$1&$2 last;這條規則在 nginx 是正常的。

ringa_leeringa_lee2713 天前484

全部回覆(1)我來回復

  • 淡淡烟草味

    淡淡烟草味2017-05-16 17:06:10

    apache 預設是忽略 querystring 的
    RewriteRule ^([a-z,/,_,0-9]*)$ index.php?route=$1& [L,QSA]

    這樣就OK了,強行執行時加上querystirng 好簡單呀

    回覆
    0
  • 取消回覆