1
votes

I am dealing with a php site, and I want first to remove all the .php extensions for the sites pages, so

www.site.com/index.php

should work with

www.site.com/index

That is already working with this .htaccess configuration, for all the site pages:

 RewriteEngine On 
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^([^\.]+)$ $1.php [NC,L]

Now I want to make user friendly the site URL with parameters , but my problem is that I can have my site products.php, with multiple params, in multiple orders, and some of them can be optional.

So here are some possibilities of the parameters combination:

www.site.com/products.php?page=1&subCategory=4&category=4
www.site.com/products.php?subCategory=2&category=1
www.site.com/products.php?page=3
www.site.com/products.php?page=3&category=3

So my problem is how to add a rule on .htaccess to transform this into a more user friendly URL like:

www.site.com/products/param-value/param-value/param-value/..

or some URL close to it.

Thanks for your help! I have checked all the topics related to .htaccess and tried the different solutions proposed but I still cannot reach to make this work.

I suspect you're either going to need to specify that each "friendly" parameter must always appear in the same place (so that they can be mapped) or you're going to need to put the parameter name into the friendly URL like site.com/products/pg=1/sc=2/and.so.on/ ... it would probably be better to write a simple PHP routing script and map up the fake URLs to real ones in a database table.CD001