2015-01-13 81 views
1

我想構建一個mod_rewrite URL,但似乎無法使查詢字符串與mod_rewrite規則一起工作。具有多個變量的HTAccess

我的代碼是:

RewriteEngine On 
Options -Multiviews 
Options -Indexes 
Options +FollowSymLinks 

RewriteBase/
RewriteRule ^(.*)/$ $1 [L,R=301] 

RewriteRule ^awards awards.php [L] 

RewriteRule ^nominees/([a-z]*)?$ /nominees.php?order=$1 [L,QSA] 
RewriteRule ^nominees/([a-z]*)?$ /nominees.php?cat=$1 [L,QSA] 

RewriteRule ^nominees/([a-z]*)/([0-9]*)$ /nominees.php?order=$1&page=$2 [L,QSA] 
RewriteRule ^nominees/([a-z]*)/([0-9]*)$ /nominees.php?cat=$1&page=$2 [L,QSA] 

RewriteRule ^nominees/([a-z]*)/([a-z]*)/([0-9]*)$ /nominees.php?cat=$1&order=$2&page=$3 [L,QSA] 
RewriteRule ^nominees/([a-z]*)/([a-z]*)$ /nominees.php?cat=$1&order=$2 [L,QSA] 

RewriteRule ^nominees/([0-9]*)$ /nominees.php?page=$1 [L,QSA] 

RewriteRule ^nominees nominees.php [L]    

RewriteRule ^register register.php [L] 
RewriteRule ^admin admin.php [L] 
RewriteRule ^login login.php [L] 
RewriteRule ^logout logout.php [L] 

如果我刪除

RewriteRule ^nominees/([a-z]*)?$ /nominees.php?cat=$1 [L,QSA] 

然後

RewriteRule ^nominees/([a-z]*)?$ /nominees.php?order=$1 [L,QSA] 

作品......我似乎無法讓我的頭周圍!

我後:

提名/平均
提名/會計師
提名/會計/平均

回答

0

正則表達式是完全相同這兩個規則,這意味着第一個規則將匹配,第二條規則完全沒有。這適用於每個完全相同的集合。您需要一些其他限定符來區分「順序」和「貓」參數。也許沿線的東西:

RewriteRule ^nominees/order/([a-z]*)?$ /nominees.php?order=$1 [L,QSA] 
RewriteRule ^nominees/cat/([a-z]*)?$ /nominees.php?cat=$1 [L,QSA] 

RewriteRule ^nominees/order/([a-z]*)/([0-9]*)$ /nominees.php?order=$1&page=$2 [L,QSA] 
RewriteRule ^nominees/cat/([a-z]*)/([0-9]*)$ /nominees.php?cat=$1&page=$2 [L,QSA] 

RewriteRule ^nominees/([a-z]*)/([a-z]*)/([0-9]*)$ /nominees.php?cat=$1&order=$2&page=$3 [L,QSA] 
RewriteRule ^nominees/([a-z]*)/([a-z]*)$ /nominees.php?cat=$1&order=$2 [L,QSA] 
+0

所以沒有辦法讓被提名人/會計師/平均人數和被提名人/平均值? – potts

+0

@potts我沒有更改底部的規則,如果它是'nominees/accountants/average',它與底部的最後一條規則相匹配。但是,你應該如何區分'?order = average'和'?cat = average'之間的區別?兩者的URL看起來都一樣。 –

+0

'nominees.php /?cat =會計師=/nominees/accountants'和'nominees.php /?order = average =/nominees/average' – potts