网站优化

网站优化

Products

当前位置:首页 > 网站优化 >

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

GG网络技术分享 2025-03-18 16:12 11


问题描述:

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

网友观点:

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; ?>

标签:

提交需求或反馈

Demand feedback