- /* Redirect user to page with the canonical ID in it. */
- if (game_id !== canon_id) {
- const new_url = request.originalUrl.replace(`/${engine}/${game_id}`,
- `/${engine}/${canon_id}`);
+ /* Redirect user to page with the canonical ID in it, also ensuring
+ * that the game ID is _always_ followed by a slash. */
+ const has_slash = new RegExp(`^/${engine}/${game_id}/`);
+ if (game_id !== canon_id ||
+ ! has_slash.test(request.originalUrl))
+ {
+ const old_path = new RegExp(`/${engine}/${game_id}/?`);
+ const new_path = `/${engine}/${canon_id}/`;
+ const new_url = request.originalUrl.replace(old_path, new_path);