组件/action/id URL方案的Apache mod_重写

组件/action/id URL方案的Apache mod_重写,apache,mod-rewrite,url-routing,Apache,Mod Rewrite,Url Routing,我有一个基于组件的系统,我正在尝试使用mod_rewrite进行一些路由。由于某些原因,我无法使语法100%正确,以便所有情况都能正常工作。以下是我只能使用最后一个的四个测试用例: /component/action/24_char_id should be rewritten as /index.php?c=component&a=action&id=24_char_id /component/24_char_id should be rewritten as /index

我有一个基于组件的系统,我正在尝试使用mod_rewrite进行一些路由。由于某些原因,我无法使语法100%正确,以便所有情况都能正常工作。以下是我只能使用最后一个的四个测试用例:

/component/action/24_char_id  should be rewritten as /index.php?c=component&a=action&id=24_char_id
/component/24_char_id  should be rewritten as /index.php?c=component&id=24_char_id
/component/action should be rewritten as /index.php?c=component&a=action
/component should be rewritten as /index.php?c=component
到目前为止,我有三条规则:

RewriteRule ^([^/]+)/(.*)/([0-9a-z]{24})?/?$ /index.php?c=$1&a=$2&id=$3 [L,QSA]
RewriteRule ^([^/]+)([0-9a-z]{24})?/?$       /index.php?c=$1&id=$2      [L,QSA]
RewriteRule ^([^/]+)(?:/(.*))?/?$            /index.php?c=$1&a=$2       [L,QSA]
URL应该按照上面的规定重写,例如/index.php?c=$1&a=$2&id=$3,其中c是组件,a是操作,id是24个字符长的id。请注意,此方案中有三种URL变体


任何帮助都将不胜感激-我被卡住了

经过一些尝试和错误后,找到了答案:

RewriteRule ^([^/]+)/?([0-9a-z]{24})?/?$ /index.php?c=$1&id=$2 [L,QSA]
RewriteRule ^([^/]+)/([a-z]+)/?([0-9a-z]{24})?/?$ /index.php?c=$1&a=$2&id=$3 [L,QSA]

问题是。。?另外,您还没有指定要如何重写这些URL。需要帮助了解其不起作用的原因-似乎并非所有情况都同时起作用。我认为在某些地方存在逻辑上的重叠。有人能帮忙吗?