“登录"在永久链接中重定向到 wp-login.php wp3.6 [英] "login" in permalink redirects to wp-login.php wp3.6

查看:52
本文介绍了“登录"在永久链接中重定向到 wp-login.php wp3.6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为自定义用户页面创建自定义登录页面,但我无法让 wordpress 停止将 login 一词重定向到 wp-login.php.

设置非常简单,我添加了一个看起来像这样的规则.account/login/?$ 产生于 index.php?account=login.我还为该自定义查询变量设置了重写标记.我设置了一些其他规则,它们都可以正常工作.

当我使用猴子人的重写分析器时,一切都正确,但在前端,每​​当我将 login 输入到 url 时,它都会将我重定向到 wp-login.php.它在哪个段输入并不重要.所以/login/account/login/dogs/bullldogs/login....都重定向到wp-login.php>

据我所知,没有任何其他包含 login 的重写规则.所以我很茫然.

作为最后一条信息,我在 wp 3.6 中工作

任何建议或想法将不胜感激.

解决方案

我面临着完全相同的问题.谷歌的帮助不是很大,所以我需要深入研究.:)

就在 wp-includes/template-loader.php 文件的顶部,您会发现这个小代码片段:

if (defined('WP_USE_THEMES') && WP_USE_THEMES)do_action('template_redirect');

如果您检查当时与该操作挂钩的函数,您会发现对 wp_redirect_admin_locations 函数的引用(钩子和函数都在 /wp-includes/canonical.php 文件 - 第 526 行).

wp_redirect_admin_locations 函数中,您会发现:

 $logins = array(home_url('wp-login.php', 'relative'),home_url('登录', '相对'),site_url('登录', '相对'),);if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $logins ) ) {wp_redirect(site_url('wp-login.php','登录'));出口;}

该问题的一个简单解决方案是将您的函数挂接到 *wp_redirect* 过滤器.像这样的东西(在你的 functions.php 中):

add_filter('wp_redirect', 'yourprefix_filter_login_redirect', 10, 2);函数 yourprefix_filter_login_redirect($location, $status){$uri = trim($_SERVER['REQUEST_URI'], '/');如果($uri === '登录'){返回假;}返回 $location;}

所以... *wp_redirect_admin_locations* 在尝试执行重定向后终止脚本,因此上述解决方案不起作用.

我现在看到的唯一其他解决方案是一起绕过该功能,这很糟糕.该函数中定义的所有其他重定向都将一起丢失...

无论如何,我最终使用的是:

 add_action('在里面',功能() {remove_action('template_redirect', 'wp_redirect_admin_locations', 1000);});

I'm trying to create a custom login page for a custom user page, but I can't get wordpress to stop redirecting the word login to wp-login.php.

Setup is pretty simple, I'm adding a rule that looks like this. account/login/?$ that yields to index.php?account=login. I also setup my rewrite tag for that custom query var. I have a couple other rules setup and they all work properly.

When I use monkey man's rewrite analyzer everything points properly, but on the front end any time I enter login into the url it redirects me to wp-login.php. It doesn't matter what segment it is entered at. so /login, /account/login, /dogs/bulldogs/login.... all redirect to wp-login.php

As far as I can tell there aren't any other rewrite rules containing login. So i'm at a loss.

As a last piece of info, i'm working in wp 3.6

Any advise or ideas would be greatly appreciated.

解决方案

I'm facing the exact same problem. Google wasn't being very helpful, so I had the need to dig in. :)

Right on top of the wp-includes/template-loader.php file, you find this little snippet of code:

if ( defined('WP_USE_THEMES') && WP_USE_THEMES )
    do_action('template_redirect');

If you inspect what functions are hooked to that action at that time, you'll find a reference to the wp_redirect_admin_locations function (both the hook and the function are declared on the /wp-includes/canonical.php file - line 526).

Within the wp_redirect_admin_locations function, you'll find this:

 $logins = array(
      home_url( 'wp-login.php', 'relative' ),
      home_url( 'login', 'relative' ),
      site_url( 'login', 'relative' ),
  );
 if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $logins ) ) {
      wp_redirect( site_url( 'wp-login.php', 'login' ) );
      exit;
  }

An easy solution for the problem, would be to hook a function of yours to the *wp_redirect* filter. Something like this (within your functions.php):

add_filter('wp_redirect', 'yourprefix_filter_login_redirect', 10, 2);
function yourprefix_filter_login_redirect($location, $status)
{
     $uri = trim($_SERVER['REQUEST_URI'], '/');

      if ($uri === 'login') {
          return false;
      }

      return $location;
}

So... The *wp_redirect_admin_locations* terminates the script after trying to preform the redirect, so the solution above won't work.

The only other solution I'm seeing right now is to bypass the function all together which kind of sucks. All the other redirects defined within that function, will be lost all together...

Anyway, what I've ended up using:

    add_action(
          'init',
          function() {
              remove_action('template_redirect', 'wp_redirect_admin_locations', 1000);
          }
      );

这篇关于“登录"在永久链接中重定向到 wp-login.php wp3.6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆