How can PHP be used in conjunction with .htaccess for URL rewriting?
When using PHP in conjunction with .htaccess for URL rewriting, you can create a rewrite rule in the .htaccess file that redirects requests to a PHP file. In the PHP file, you can then parse the URL and determine the appropriate content to display based on the rewritten URL.
// .htaccess
RewriteEngine On
RewriteRule ^example/([a-zA-Z0-9-]+)$ example.php?url=$1 [L]
// example.php
<?php
$url = $_GET['url'];
switch ($url) {
case 'about':
include 'about.php';
break;
case 'contact':
include 'contact.php';
break;
default:
include '404.php';
}
?>