0

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']; 
2
  • 1
    Possible duplicate of User-friendly URLs instead of Query Strings? Commented Oct 15, 2017 at 16:46
  • Yes, I didn't know it was called friendly URLs. The one you linked to had only broken links, but I found some other guides which finally helped me thanks to the phrase friendly URLs. I will update the question. Commented Oct 15, 2017 at 17:33

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.