You'll need to do this in Apache using mod_rewrite. You'll need to redirect all URLs to to your index.php and then, maybe using parse_url, figure out what to do with them.
For example:
# Turn on the rewrite engine
RewriteEngine On
# Only redirect if the request is not for index.php
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is not for an actual file
RewriteCond %{REQUEST_FILENAME} !-f
# or an actual folder
RewriteCond %{REQUEST_FILENAME} !-d
# finally, rewrite (not redirect) to index.php
RewriteRule .* index.php [L]