php - .htaccess make URL user friendly for multiple and dynamic parameters

柔情痞子 提交于 2019-12-11 04:25:11

问题


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.

来源:https://stackoverflow.com/questions/37485609/php-htaccess-make-url-user-friendly-for-multiple-and-dynamic-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!