What are the best practices for hiding URLs in a PHP application to improve security and user experience?

Hiding URLs in a PHP application can improve security by preventing direct access to certain pages and enhance user experience by making the URL structure cleaner. One way to achieve this is by using URL rewriting techniques, such as using mod_rewrite in Apache or routing mechanisms in frameworks like Laravel.

// Example of using mod_rewrite in .htaccess file to hide URLs
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>