本文介绍了add_rewrite_rule字preSS与W3总缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图重写规则,搜索引擎友好的。这里是code我把我的主题function.php
I am trying to rewrite rule to seo friendly.Here is the code I put in my theme function.php
add_action('init', 'add_my_rewrite_rule');
function add_my_rewrite_rule(){
add_rewrite_rule('^quiz/([^/]*)/([^/]*)?','index.php?pagename=quiz&quiztitle=$matches[1]&quizid=$matches[2]','top');
}
add_filter('query_vars','set_quiz_query_var');
function set_quiz_query_var($vars) {
array_push($vars, 'quiztitle');
array_push($vars, 'quizid');
return $vars;
}
由于这个片段没有工作,我也试图重写的.htaccess规则。
Because this snippet didn't work, I also tried to rewrite .htaccess rule.
RewriteRule ^quiz/([^/]+)/([^/]+)$ /index.php?pagename=quiz&quiztitle=$1&quizid=$2 [NC,R=301,L]
我想这是因为W3总缓存。我花了整整一夜,但不能算出它独自....
I guess this is because of w3 total cache. I spent whole night but couldn't figure it out alone....
推荐答案
对不起,回答我!我花了整个晚上和白天找出问题。
Sorry for answering myself! I spent whole night and day to find out the issue.
我用的add_filter代替add_action和它的工作。
I used add_filter instead of add_action and it worked out.
add_filter('rewrite_rules_array','add_my_rewrite_rule');
function add_my_rewrite_rule($rules)
{
$newrules = array();
$newrules['^quiz/([^/]+)/([^/]+)/?'] = 'index.php?pagename=quiz&quiztitle=$matches[1]&quizid=$matches[2]';
return $newrules + $rules;
}
这篇关于add_rewrite_rule字preSS与W3总缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!