Is it possible to define optional route segments? Is it possible to have optional route segments/variables with getCpRoutes() and getSiteRoutes()?

I'd like the following route to work, even if the URI only contains one segment ("myplugin") rather than two ("myplugin/somevalue"):

"myplugin/(?P&lt;myVariable&gt;[-\w]+)" =&gt; array( "action" =&gt; "myPlugin/myAction" )


How would the regexp look? Is it even possible, or do I need another route pointing to the same action, but omitting the myVariable segment?

This question is kind of a follow up to Route that should be matching numbers not matching a zero?
You can make a capturing group optional, simply append ? to it. In this case you'd need to add an additional group that includes the backslash and make it optional.

"myplugin(/(?P&lt;myVariable&gt;[-\w]+))?" =&gt; array("action" =&gt; "myPlugin/myAction")