实际网址如下 -
/category.php?id=2
和/product.php?id=56
。我在htaccess文件中应用了以下规则 -
RewriteEngine On
RewriteRule ^.+/p/([0-9]+) product.php?id=$1 [NC,L]
RewriteRule ^.+/c/([0-9]+) category.php?id=$1 [NC,L]
我得到以下网址模式 -
/c/2 and `/p/56`
到此为止它很好
以前我可以通过GET方法从类似?id= 2
获取类别和产品的ID。但重写后get方法将无效。如何获取ID以及页面类型(类别,产品)?
答案 0 :(得分:1)
试试这个
RewriteEngine On
RewriteRule ^.+/p/([0-9]+) product.php?id=$1 [QSA,L]
RewriteRule ^.+/c/([0-9]+) category.php?id=$1 [QSA,L]
QSA意味着如果有一个与原始URL一起传递的查询字符串,它将被附加到重写。
L表示如果规则匹配,则不再处理此规则以下的RewriteRules。