I’m trying to make a rewrite rule for d3 visualizations that I’ll be keeping in my theme folder. Ultimately I want
d3/[some-year]/[some-string]
to redirect to
wp-content/themes/my-theme/d3-library/[some-year]/[some-string]/index.html
However, I can’t get the capture rules to work. Here’s what I have so far:
function d3_rewrite() {
add_rewrite_rule(
'wp-content/themes/d3/(20[0-9][0-9]/.*)',
'wp-content/themes/my-theme/assets/d3-library/$match[1]/index.html',
'top'
);
}
add_action('init', 'd3_rewrite');
Does anyone know why this doesn’t work?
Use
wp-content/themes/my-theme/assets/d3-library/$1/index.html
. The problem is in the replacement back-reference.Where you have
$match[1]
, shouldn’t that be$matches[1]
?