I assumed the custom routes were applied in order - i.e. if a match was found the process stopped.
I had an issue this evening which I could not understand. Finally I moved the custom route to the end of the file and it worked.
Is this correct?
The url was: http://websiteaddress/eandwhmi/search/dsjhdjsdh
Custom Routes Order
2 years ago
2 years ago
#1
2 years ago
#2
Hey there,
It appears that the custom routes are indeed applied in the order they are defined. If you follow the logic in 'attempt_add_custom_routes()When a URL is matched with a custom route, the corresponding destination is substituted, and the process continues until all routes are checked. If the custom route that matches your URL is defined later in the array, it will take precedence over previous routes.
Moving the problematic custom route to the end of the array likely resolved the issue because it ensured that other more specific routes were checked first before attempting to match the URL against that particular route.
So, yes, your understanding is correct. Custom routes are applied in the order they are defined, and if a match is found, the process stops. Moving the custom route to the end of the file, as you did, is a valid approach to ensure that it is only considered after other routes have been checked.
It appears that the custom routes are indeed applied in the order they are defined. If you follow the logic in 'attempt_add_custom_routes()When a URL is matched with a custom route, the corresponding destination is substituted, and the process continues until all routes are checked. If the custom route that matches your URL is defined later in the array, it will take precedence over previous routes.
Moving the problematic custom route to the end of the array likely resolved the issue because it ensured that other more specific routes were checked first before attempting to match the URL against that particular route.
So, yes, your understanding is correct. Custom routes are applied in the order they are defined, and if a match is found, the process stops. Moving the custom route to the end of the file, as you did, is a valid approach to ensure that it is only considered after other routes have been checked.