Push URLs through index.php?

I’m re-developing my website and want to have a cleaner structure throughout.

ideally i’d like to use a file like index.php to contain the essential includes, error reporting/handling, database connection etc, now if all pages are pushed through this then i understand i only need to declare them once and then they’ll always be available to all pages on the website?

i know i can do something like this with htaccess

RewriteCond %{REQUEST_URI} ^
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)?$ /index.php [L]

For the most part this works but when i have deeper urls it doesn’t work properly.

for example i might have a blog post

…com/blog/hello-world (blog.php?post=hello-world)

How would i get my application to register this?

i will also have urls like

…com/gallery/album/photo-album (gallery.php?album=album&photo=photo-name)

i feel i may need to restructure my files?

I guess in a way i want to build a mini framework with the mvc pattern and then call everything through index. what is the best way to do this?

What you are looking for is called a Front Controller

Thank you, now to just find the best implementation