繁体   English   中英

如果引荐来源网址不匹配,则有条件重定向WordPress

[英]Conditional redirect WordPress if referrer URL not match

我尝试添加条件登录,如果页码匹配和wp_get_referer匹配机智$ value做动作,但我不知道我卡住了一些

add_action( 'template_redirect', 'wpse15677455_redirect' );

function wpse15677455_redirect() {
  $ref = wp_get_referer();
  $value = ('https://mywebsite.com/quotaton/') ;
    if (!is_page(555)) & $ref => $value {
        wp_redirect( home_url() ); 
        // exit; //( I also dont know if need exit if i add this code in function)
    }
 };

我也认为这是我不知道的解决方案

add_action( 'template_redirect', 'wpse15677455_redirect' );
 function wpse156774_redirect() {
    $ref = wp_get_referer();
    if (is_page(555)) &&  if (strpos($ref, 'quotaton') !== false) {
        echo 'true';
    }
};

提前致谢

我不清楚您的问题。 但是我想您正在寻找这个。

add_action( 'template_redirect', 'wpse15677455_redirect' );

function wpse15677455_redirect() {

  $value = ('https://mywebsite.com/quotaton/') ;
    if (!is_page(555) & wp_get_referer() !== $value ) {

       wp_safe_redirect( get_home_url() );

    }
 };

了解条件后,我便找到了解决方案:

add_action( 'template_redirect', 'wpse1567745555_redirect' );  
function wpse1567745555_redirect() {
  $ref = wp_get_referer();
    if (is_page(227) && $ref == "https://mywebsite/quotaton/") {
        //echo 'Its Working Let it Continue';
    }
    else if (is_page(227) && $ref !== "https://mywebsite/quotaton/"){
        wp_redirect( 'https://mywebsite/sorry/', 301 ); exit;
        // Not Working Let's Redirect and exit 
    }
    else if (!is_page(227)){
          // echo 'Its Not Need Anything Here';
    }
}

如果您只希望允许用户访问来自特定URL的特定页面,则以上代码对WordPress很有用。

如果有任何建议,请添加它们。

暂无
暂无

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

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