Regex Apache重写规则允许斜杠或指定值后为空

Regex Apache重写规则允许斜杠或指定值后为空,regex,apache,mod-rewrite,url-rewriting,Regex,Apache,Mod Rewrite,Url Rewriting,我需要以下Apache重写规则的帮助 RewriteRule^(客户)/(活动的|创建)/?$/mod/customers/?type=$2[NC,L] 此规则仅在/后面有内容时有效,例如:http://example.com/customers/active 如果url是http://example.com/customers 如何编写此重写规则,以便http://example.com/customers和http://example.com/customers/active /custom

我需要以下Apache重写规则的帮助

RewriteRule^(客户)/(活动的|创建)/?$/mod/customers/?type=$2[NC,L]

此规则仅在
/
后面有内容时有效,例如:
http://example.com/customers/active

如果url是
http://example.com/customers

如何编写此重写规则,以便
http://example.com/customers
http://example.com/customers/active


/customers
后跟nothing,或
/customers
后跟
/active
/create
您可以使用此正则表达式:

^(customers)(?:/(active|create))?/?$
它使用可选的非捕获组来允许URL,例如
http://example.com/customers
以及
http://example.com/customers/active
。“活动”创建仍在组2中捕获

此正则表达式允许URL上有一个尾随的
/
,例如
http://example.com/customers/
http://example.com/customers/active/
。如果不需要,只需删除
$
前面的
/?
,即

^(customers)(?:/(active|create))?$

关于
http://example.com/customers/
http://example.com/customers/active/
?您的意思是尾随的
/
?是的,允许吗?当前URL中没有尾随的
/
。这很好。如果我需要
active
后跟字母和长度在10到20个字符之间的数字,我如何将其添加到上述规则中<代码>例如:example.com/customers/active/a1dx12s5e4jklo@Norman也许?允许
活动
活动
后跟
/
和10-20个字符。如果必须有字符,请删除
(/[a-z]{10,20}
组后面的