How does WordPress handle content organization through directories while still loading index.php?id=123?

WordPress handles content organization through directories by utilizing its internal rewrite rules. This allows WordPress to load the appropriate content based on the URL structure, even if it includes parameters like index.php?id=123. To ensure proper organization, developers can create custom rewrite rules in the functions.php file of their theme or use plugins like Yoast SEO to manage URL structures.

function custom_rewrite_rule() {
    add_rewrite_rule('^custom-page/([^/]+)/?', 'index.php?id=$matches[1]', 'top');
}
add_action('init', 'custom_rewrite_rule');