I need help with the following Apache RewriteRule
RewriteRule ^(customers)/(active|create)/?$ /mod/customers/?type=$2 [NC,L]
This rule works only if there's something after the / Eg: http://example.com/customers/active
It won't work if the url is http://example.com/customers
How can this RewriteRule be written so http://example.com/customers will work, as well as http://example.com/customers/active
/customers followed by nothing, or /customers followed by /active or /create
You can use this regex:
^(customers)(?:/(active|create))?/?$
It uses an optional non-capturing group to allow for a URL such as http://example.com/customers as well as http://example.com/customers/active. The `active|create is still captured in group 2.
This regex allows for a trailing / on the URL e.g. http://example.com/customers/ or http://example.com/customers/active/. If that is not desired, just remove the /? in front of the $ i.e.
^(customers)(?:/(active|create))?$