【问题标题】:How can I redirect wp-admin to another url如何将 wp-admin 重定向到另一个 url
【发布时间】:2014-11-26 03:31:26
【问题描述】:

如何将用户从 wp-admin 重定向到另一个自定义页面,例如我想重定向这个 url:

http://example.com/wp-admin

到:

http://example.com/custom

【问题讨论】:

    标签: php wordpress .htaccess redirect


    【解决方案1】:
    wp_redirect( $location, $status );
    exit;  
    

    或者像这样尝试

    wp_redirect( home_url( '/custom/' ) );
    exit();
    

    【讨论】:

      【解决方案2】:

      最简单的方法可能是在您的webroot directory 中创建一个.htaccess 文件。

      然后把这个写进去:

      Redirect /wp-admin http://www.example.com/custom
      

      非常不言自明。 Redirect 从第一个链接 /wp-admin 到第二个链接 http://www.example.com/custom

      另一种方法可能是使用 wordpress wp_redirect() 函数,如下所示:

      wp_redirect('http://example.com/custom', $status );
      

      【讨论】:

      • @Resolution 里面的wp-login.php
      【解决方案3】:

      在您的 functions.php 文件中使用以下代码重定向到另一个 URL。

      function redirect_login_page(){
      
       // Store for checking if this page equals wp-login.php
       $page_viewed = basename($_SERVER['REQUEST_URI']);
      
       // Where we want them to go
       $login_page  = http://example.com/custom; //Write your site URL here.
       // Two things happen here, we make sure we are on the login page
       // and we also make sure that the request isn't coming from a form
       // this ensures that our scripts & users can still log in and out.
       if( $page_viewed == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') {
      
       // And away they go...
        wp_redirect($login_page);
        exit();
      
       }
      }
      
      add_action('init','redirect_login_page');
      

      【讨论】:

        猜你喜欢
        • 2012-08-28
        • 2019-07-25
        • 1970-01-01
        • 2012-09-08
        • 2014-05-06
        • 1970-01-01
        • 2017-05-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多