I think you need a limit on the explode, otherwise this function will just match paths that are first level. 

Ex, It will match "contact" but not "contact/us"