Instead of
http://example.com/file.php?color=red
I would like to use
http://example.com/file/red
I have removed my file extensions by adding the code below to .htaccess which will display the content of the http://example.com/file.php on the server when accessing http://example.com/file/
Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / ## hide .php extension # To externally redirect /dir/foo.php to /dir/foo RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1 [R,L,NC] ## To internally redirect /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^ %{REQUEST_URI}.php [L] Now I am looking for a way to pass the "red" parameter to the file when putting this address in the web browser like this http://example.com/file/red
Thanks!
EDIT: I got the answer to look for something called friendly URLs and that helped me.
I ended up with replacing the first code with this.
Options -MultiViews RewriteEngine On # redirect "/file.php?id=xxx" to "/file/xxx" RewriteCond %{THE_REQUEST} \s/file\.php\?color=([A-Za-z0-9_]+)\s [NC] RewriteRule ^ /file/%1? [R=301,L] # internally rewrite "/file/xxx" to "/file.php?id=xxx" RewriteRule ^file/([A-Za-z0-9_]+)$ file.php?color=$1 [L] Then with PHP I will just request the parameter like this.
$color = $_GET['color'];