2015-06-01 77 views
0

我有這樣如何重寫多個單PARAMS在URL

http://be.ac/index.php?category=all&providers=all&keyword=cookies&page=1 

我想重寫這樣的網址:

http://be.ac/category/all/providers/all/keyword:cookies/page:1 

這是我的htaccess

RewriteEngine on 
RewriteRule ^page:([^/]*)/?$ index.php?page=$1 [QSA,L] 
RewriteRule ^category/([^/]*)/?$ index.php?category=$1 [QSA,L] 
RewriteRule ^category/([^/]*)/page:([^/]*)/? index.php?category=$1&page=$2 [QSA,L] 
RewriteRule ^category/([^/]*)/providers/([^/]*)/page:([^/]*)? index.php?category=$1&providers=$2&page=$3 [QSA,L] 
RewriteRule ^category/([^/]*)/providers/([^/]*)/keyword:([^/]*)/page:([^/]*)? index.php?category=$1&providers=$2&keyword=$3&page=$4 [QSA,L] 

這是行不通的,我需要的是接受像這樣的網址:

http://be.ac/category/all/providers/all/keyword:cookies/page:1 
http://be.ac/category/all/providers/all/page:1 
http://be.ac/category/all/page:1 
http://be.ac/page:1 
http://be.ac/keyword:cookies 

有什麼想法?

回答

0

我相信問題是關於冒號。首先猜測是他們需要被編碼,除非在散列字符串中。

因此,你會得到一個403 Forbidden錯誤拋出 - 雖然,你沒有在你的問題中指定。

我可以推薦在切換出去斜槓那些冒號的唯一的事,這使URI是一致的(像你用category/<something>代替category:<something>完成):

RewriteEngine on 
RewriteRule ^page/([^/]+)/?$ index.php?page=$1 [QSA,L] 
RewriteRule ^category/([^/]+)/?$ index.php?category=$1 [QSA,L] 
RewriteRule ^category/([^/]+)/page/([^/]+)/? index.php?category=$1&page=$2 [QSA,L] 
RewriteRule ^category/([^/]+)/providers/([^/]+)/page/([^/]+)/?$ index.php?category=$1&providers=$2&page=$3 [QSA,L] 
RewriteRule ^category/([^/]+)/providers/([^/]+)/keyword/([^/]+)/page/([^/]+)/?$ index.php?category=$1&providers=$2&keyword=$3&page=$4 [QSA,L] 

而且,我已經改變了([^/]*)([^/]+),並修正了最後兩個問題的尾部斜線問題(它們與其他問題不一致)。