【发布时间】:2018-04-17 09:53:34
【问题描述】:
我有一个安装了 WooCommerce 和 Avada 主题的 WordPress 网站。我正在尝试通过functions.php 文件执行重写规则。
我希望到达 http://example.com/product/SKU01 的内容必须重定向到 http://example.com/custom-file.php?prod_sku=SKU01
add_action('init', 'dcc_rewrite_tags');
function dcc_rewrite_tags() {
add_rewrite_tag('%propref%', '([^&]+)');
}
add_action('init', 'dcc_rewrite_rules');
function dcc_rewrite_rules() {
add_rewrite_rule('^product/?$','custom-file.php?prod_sku=$matches[1]','top');
}
在插件(Rewrite Rule Inspector) 中,我可以看到一切正常,但是当我尝试在前端打开 URL 时,它无法正常工作。
这根本不起作用。我的 WooCommerce 在其 URL 中不使用任何“产品”字符串,但它根本不起作用。我也试过.htaccess,但我得到了同样的行为。每次我拨打/product/sku01 都会被重定向到404 页面。
【问题讨论】:
-
您是否访问过永久链接选项页面(我不确定它是否被命名为“永久链接”novadays)?访问这里会触发一些重新加载重定向方法,这可以帮助你。
-
@bigwolk 是的,但根本不工作。我还刷新了重写规则