具有多个变量的 HTAccess

HTAccess with multiple variables

我正在尝试构建 mod_rewrite URL 但似乎无法让查询字符串与 mod_rewrite 规则一起工作。

我的代码是:

RewriteEngine On
Options -Multiviews
Options -Indexes
Options +FollowSymLinks

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

RewriteRule ^awards awards.php [L]

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

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

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

RewriteRule ^nominees/([0-9]*)$ /nominees.php?page= [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= [L,QSA]

然后

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

有效...我似乎无法理解它!

我在追求:

nominees/average
nominees/accountants
nominees/accountants/平均

两个规则的正则表达式完全相同,这意味着第一个规则将匹配而第二个规则完全不执行任何操作。这适用于您的每个完全相同的集合。您需要一些其他限定符来区分 "order" 和 "cat" 参数。也许是这样的:

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

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

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