将两个$ _GET变量拆分为路径

将两个$ _GET变量拆分为路径

问题描述:

I'm trying to write a rewrite rule that works something like:

www.sitename.com/products.php?p=product&c=category 

should become

www.sitename.com/product/category

I have tried the following, but my RegEx knowledge is far from ideal and the following does not work

RewriteRule ^(.*)/(.*)$ products.php?p=$1&c=$2 [QSA,L]

Any help is greatly appreciated!

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/([\w-]+)/?$ products.php?p=$1&c=$2 [QSA,L]

RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)\.html$ $1.php [NC,L]

Try replacing (.*) with ([^/]+)

Try something like this:

RewriteRule www.sitename.com/(.*)/(.*) $products.php?p=$1&c=$2 [QSA,L]

You can test your rewrite rules in this site.