简体   繁体   English

重写URL wordpress不起作用

[英]rewrite url wordpress not working

my wordpress url is like below i want to rewrite it 我的WordPress的URL就像下面我想重写它

http://twowebse.website/course-instance/course-2-19-21-jan-2018/?crse=result to http://twowebse.website/course-instance/course-2-19-21-jan-2018/crse/result http://twowebse.website/course-instance/course-2-19-21-jan-2018/?crse=返回http://twowebse.website/course-instance/course-2-19-21-jan的结果-2018 / crse /结果

i have tried below rewrite but it does not seem to be working.maybe because of dynamic url comes between for eg.course-2-19-21-jan-2018 我已经尝试过下面的重写,但它似乎无法正常工作。也许是因为动态URL出现在例如Course-2-19-21-jan-2018之间

course-instance=taxonomy 课程实例=分类
course-2-19-21-jan-2018=taxonomyterm course-2-19-21-jan-2018 =分类术语

crse i am apending static query variable crse我正在附加静态查询变量

add_filter( 'query_vars', 'wpse12965_query_varss' );
function wpse12965_query_varss( $query_vars )
{
    $query_vars[] = 'crse';
    return $query_vars;
}


add_action( 'init', 'wpse12065_inits' );
function wpse12065_inits()
{
    add_rewrite_rule(
        'course-instance/(/([^/]+))?(/([^/]+))?/?',
        'index.php?pagename=course-instance&$matches[2]&crse=$matches[4]',
        'top'
    );
}

Without having much knowledge on your structure I can guess your rewrite structure will be somewhat similar to the following, 如果您对结构没有太多了解,我猜您的重写结构将与以下结构类似,

add_rewrite_rule('^course-instance/([a-zA-Z]*)/([0-9a-zA-Z]*)/([a-zA-Z]*)/([a-zA-Z]*)',
    'index.php?pagename=course-instance&page=$matches[2]&**some-key**=crse&crse=$matches[4]',
    'top'
);

remove some-key with the type of this keyword in your structure. 在您的结构中删除带有此关键字类型的some-key

Otherwise remove 3rd parameter totally from your URL. 否则,请从您的网址中完全删除第3个参数。 By doing that your URL will be, 这样,您的网址将会是

http://twowebse.website/course-instance/course-2-19-21-jan-2018/result http://twowebse.website/course-instance/course-2-19-21-jan-2018/result

add_rewrite_rule('^course-instance/([a-zA-Z]*)/([0-9a-zA-Z]*)/([a-zA-Z]*)',
    'index.php?pagename=course-instance&page=$matches[2]&crse=$matches[3]',
    'top'
);

Hope this helps :) 希望这可以帮助 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM