doujia4619 2019-05-14 23:04 采纳率: 0%
浏览 67
已采纳

Wordpress添加重写规则重定向而不是“隐藏”

I made a wordpress "add_rewrite_rule" to access 2 GET variables in a clean way.

But so far, it only redirects instead of "cloaking", it also loses the GET variables. (The site uses polylang as a plugin)

I tried including the add_rewrit_rule, adding the values as "tags", ...

function activateresetrule() {

    add_rewrite_rule(
        '^reset/([^/]*)/([^/]*)/?$',
        'index.php?page_id=1330&email=$matches[1]&uuid=$matches[2]',
        'top'
    );

    add_rewrite_rule(
        '^activate/([^/]*)/([^/]*)/?$',
        'index.php??page_id=1325&email=$matches[1]&uuid=$matches[2]',
        'top'
    );
    //delete when fixed
    global $wp_rewrite;
    $wp_rewrite->flush_rules(false);  
}
add_action( 'init', 'activateresetrule' );

add_filter( 'query_vars', 'activateresetrule_filter' );
function activateresetrule_filter( $query_vars ){
    $query_vars[] = 'email';
    $query_vars[] = 'uuid';
    return $query_vars;
}

Goal: https://www.site.be/reset/dfsdf/ddfsfds/ should be the same as https://www.site.be/reset&email=dfsdf&uuid=ddfsfds

Current redirect: /dashboard/password-reset-mail/ (no GET variables) (This is page_id 1330)

Thankyou

  • 写回答

1条回答 默认 最新

  • douyao1994 2019-05-16 22:08
    关注

    Found the solution:

    Existing WP pagina: /dashboard/password-reset-mail/?email=info@maximdegroote.be&uuid=96819e7d-c124-4610-9ae9-62ddb4adf678

    The new URL: /reset/info@maximdegroote.be/96819e7d-c124-4610-9ae9-62ddb4adf678/

    functions.php

    function rewriteurl() {
      global
      $wp,$wp_rewrite;
      $wp->add_query_var('email');
      $wp->add_query_var('uuid');
      $wp_rewrite->add_rule('^reset/([^/]*)/([^/]*)/?$', 'index.php?post_type=dashboard&page_id=1330&email=$matches[1]&uuid=$matches[2]', 'top');
    
      // Reset permalinks, delete after programming
      $wp_rewrite->flush_rules(false);  
    }
    

    thepage.php

    $email = $wp->query_vars['email']; echo $email;
    $uuid = $wp->query_vars['uuid']; echo $uuid; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化