【发布时间】:2014-04-18 20:46:34
【问题描述】:
我正在尝试使用 add_rewrite_rules 为 Wordpress 网站构建过滤功能。我有以下链接示例
example.com/offers-type-all-inclusive-from-germany-transportation-airplane.html
使用以下重写规则:
add_rewrite_rule('^offers-type-?([a-z0-9-]+)?-from-?([a-z-]+)?-transportation-?([a-z0-9-]+)?.html','index.php?filters=offers&type=$matches[1]&location=$matches[2]&transportation=$matches[3]','top');
我设法将用户重定向到自定义页面模板,并将参数存储为数组
array(
'type' => 'all-inclusive',
'from' => 'germany',
'transportation' => 'airplane'
);
问题是某些参数可能是可选的,因此像
这样的链接example.com/offers-type-all-inclusive-from-germany.html
example.com/offers-type-all-inclusive-transportation-airplane.html
还需要建立正确的过滤数组。
是否有可能实现这一目标?
【问题讨论】:
-
参数中也用“-”分隔时,是否需要用“-”?为什么不 example.com/offers-type/all-inclusive/from-germany/transportation-airplane?
标签: php regex wordpress url-rewriting rewrite