How can PHP developers efficiently handle situations where multiple URLs need to display the same content without duplicating physical server content?
When multiple URLs need to display the same content without duplicating physical server content, PHP developers can use URL rewriting techniques to map different URLs to the same physical file. This can be achieved by configuring the web server to rewrite URLs or by using PHP to parse the requested URL and serve the appropriate content dynamically.
<?php
// URL rewriting using PHP
$requested_url = $_SERVER['REQUEST_URI'];
// Mapping different URLs to the same content
if ($requested_url == '/page1') {
include('content.php');
} elseif ($requested_url == '/page2') {
include('content.php');
} else {
// Handle other URLs or show a 404 error
echo 'Page not found';
}
?>