Personal Catalogue: PHP & MySQL — Chapter 10, Exercise 2 ==================================================== TASK Update every header('Location: ...') redirect across add_item.php, edit_item.php, and delete_item.php to use a relative path instead of an absolute one (per this chapter's own warning), then confirm the app still works correctly whether it's mounted at the web root or at /catalogue/. SOLUTION The changes, one per file: add_item.php (Chapter 3, extended in Chapter 8): // Before: header("Location: /add_item.php?added=1&last_type={$itemTypeId}"); // After: header("Location: add_item.php?added=1&last_type={$itemTypeId}"); edit_item.php (Chapter 3): // Before: header("Location: /edit_item.php?id={$id}&updated=1"); // After: header("Location: edit_item.php?id={$id}&updated=1"); delete_item.php (Chapter 3): // Before: header('Location: /index.php?deleted=1'); // After: header('Location: index.php?deleted=1'); A relative Location header (one with no leading /) is resolved by the browser against the current request's own directory, per the standard HTTP redirect resolution rule — so from a request to /add_item.php, "add_item.php" resolves to /add_item.php (root-mounted case), while from a request to /catalogue/add_item.php, the same relative "add_item.php" resolves to /catalogue/add_item.php (path-mounted case) — automatically correct in both cases with no mount-path-specific logic needed anywhere in the PHP code. To confirm: test the app fully (add an item, edit it, delete it) first with the app served at the web root, confirming each redirect lands on the expected page with no 404. Then move (or reverse-proxy) the exact same, unmodified code to /catalogue/ per Exercise 1's own nginx setup, and repeat the same three actions — every redirect should still correctly land on the equivalent /catalogue/-prefixed page, with no code change needed between the two deployments. WHY THIS WORKS AS AN ANSWER ---------------------------- It changes every real redirect the chapter's own warning identified (not just one example), explains the actual HTTP mechanism that makes a relative Location header mount-path-independent, and verifies the fix concretely by testing the identical, unmodified code at two different mount points rather than only reasoning about it abstractly.