Fix the AJAX URLs instead
With regards to the explanation in your comment, I would argue that the "correct" way of fixing this problem is to use proper root relative URLs for the AJAX calls, as changing the URL structure only cloakes the underlying problem, that is targeting non-unique resources.
Personally I alwas use Router::url() to generate the URLs, either in the specific script files when serving them via PHP, or by writing out configuration in for example the layout, being it globally so that the scripts can access it when needed:
<script>
var config = {
navigationDataUrl: <?php echo json_encode(
Router::url(array('controller' => 'Navigations', 'action' => 'get_data'))
) ?>
};
</script>
or by configuring possibly existing JS objects.
<script>
navigation.dataUrl = <?php echo json_encode(
Router::url(array('controller' => 'Navigations', 'action' => 'get_data'))
) ?>;
</script>
Connect routes with an explicit index part
That being said, for the sake of completion, it is possible to force the index part to not be dropped, by connecting routes that explicitly define that part, as opposed to using the :action route element, like:
Router::connect('/:controller/index', array('action' => 'index'));
which would match/catch URL arrays like yours before they are being handled by CakePHPs default controller index catchall route, which looks like:
Router::connect('/:controller', array('action' => 'index'), array('defaultRoute' => true));
https://github.com/cakephp/cakephp/blob/2.10.6/lib/Cake/Config/routes.php#L72
indexas a default action. So that routing only matches when an action is defined. I would post an answer, but I don't remember Cake 2 routing very well.$.get('get_data'). This will result in a 404 if you're accessing the page as/navigationsbut if it contains a trailing slash/navigations/it will work fine. The reason for this is because the ajax request should be made to, for example,https://localhost/navigations/get_datawhereas without the trailing slash it will requesthttps://localhost/get_data(404 error as that doesn't exist). The alternative is to replace all the URL's in the ajax requests.$.get('get_data')is a code smell. You shouldn't write code that makes assumptions about the URL state.