Regex Apache重写规则允许斜杠或指定值后为空
我需要以下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
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}
组后面的?
。