How can PHP be used to create custom URLs for different pages on a website?

To create custom URLs for different pages on a website using PHP, you can use URL rewriting techniques. This involves rewriting the URL in a user-friendly format that masks the actual file structure on the server. This can be achieved by using the .htaccess file to redirect requests to a central PHP script that parses the URL and loads the appropriate page content dynamically.

// .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

// index.php file
$url = $_GET['url'];
switch ($url) {
    case 'about':
        include 'about.php';
        break;
    case 'contact':
        include 'contact.php';
        break;
    default:
        include 'home.php';
}