我有这个网址
category/product/index.php?itemid=WdS7Dk3L&title=new-product
我想将其重写为此,其中第二个参数是可选的
category/product/WdS7Dk3L/new-product
或
category/product/WdS7Dk3L/
我的htaccess放在
category/product/.htaccess
我已经从这篇文章中得到了,但是我无法使它正常工作。
RewriteRule ^category/product/([^/]*)/?(.*)$ index.php?itemid=$1&title=$2
请帮助我指出正确的方向。谢谢。
.htaccess
文件重写匹配是相对于.htaccess
文件位置的,因此使用此命令:
RewriteRule ^([^/]+)(?:/(.*))?$ index.php?itemid=$1&title=$2
您仅将第二个参数指定为可选参数,因此我将第一个*(零或多个)更改为+(一个或多个,如此处所示),并删除了?(可选),因为在两个示例中都使用了斜线。
更新
没有提供第二个参数时,匹配已更新,以使第一个参数后的斜杠为可选。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句