They cannot be optional, no. If you need that, you need two methods to handle them.
This reflects the nature of path variables – it doesn’t really make sense for them to be null. REST-style URLs always need the full URL path. If you have an optional component, consider making it a request parameter instead (i.e. using @RequestParam). This is much better suited to optional arguments.