I have a small PHP MVC framework which runs on a droplet that uses Ubuntu and I'm trying to make all the URLs 'friendly'. From:
index.php?u=controller/method/param
To:
controller/method/param
For that I'm using a .htaccess
file containing this code:
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?u=$1 [L,QSA]
With this I can make the URL friendly, but the unfriendly URL is still there. Therefore I can access the same content both ways:
index.php?u=controller/method/param
That is the same as:
controller/method/param
How do I force the URL to always be friendly? No more index.php?u=
?
Use the below rule, we are redirecting any request to index.php which has u query param to newly created pretty url.