Support » Plugin: Member Access » [Plugin: Member Access] Problems with MemberAccess and htaccess rewrite rule

Viewing 2 replies - 1 through 2 (of 2 total)
  • After spending all day on this, I’ve solved my own problem.
    Here’s what I did, in case it helps someone else:

    It seems that when the plugin catches a non-logged in user trying to view protected content, it creates a $redirect_to variable, which it then passes to wp-login.php.

    $redirect_to = urlencode($proto . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);

    The problem is, that if I enter ‘http://www.mysite.com/blog’, $_SERVER['HTTP_HOST'] will hold ‘www.mysite.com’. If site address is set to ‘http://mysite.com’ in my WP backend however, this will confuse the login script and the user will end up at the dashboard (presumably by default).

    To sort this out, one could hard code the site url into the $redirect_to variable, although this is a bit ugly.

    Alternatively, one could check if site_url() starts with ‘www.’ and if it doesn’t, remove it from $_SERVER['HTTP_HOST']

    Something like this:

    if (preg_match('/^www./', site_url())){
      $host= $_SERVER['HTTP_HOST'];
    }else{
      $host = preg_replace('/www./', '', $_SERVER['HTTP_HOST'], 1);
    }
    $redirect_to = urlencode($proto . $host . $_SERVER['REQUEST_URI']);

    Oops, I forgot to mask the dot after the www in the reg exp.
    It should be:
    $host = preg_replace('/www\./', '', $_SERVER['HTTP_HOST'], 1);

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Member Access] Problems with MemberAccess and htaccess rewrite rule’ is closed to new replies.