How can .htaccess and PHP be combined to handle URL redirection and content generation effectively in PHP applications?
Combining .htaccess and PHP allows for efficient handling of URL redirection and content generation in PHP applications. .htaccess can be used to redirect URLs and rewrite them to point to PHP scripts, while PHP can dynamically generate content based on the URL parameters. This combination enables flexible routing and content generation within PHP applications.
// .htaccess
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /index.php?page=$1&section=$2 [L]
// index.php
<?php
$page = isset($_GET['page']) ? $_GET['page'] : 'home';
$section = isset($_GET['section']) ? $_GET['section'] : 'main';
// Generate content based on $page and $section
?>