【问题标题】:Can't access site on mobile手机无法访问网站
【发布时间】:2018-05-16 15:36:46
【问题描述】:

我有一个 WordPress 网站。我创建了一个页面模板,仅用于访问者的索引页面(它在 Wordpress 管理设置 -> 阅读中设置为主页)。我在页面模板中使用了以下代码来实现这一点:

if( is_user_logged_in() ) {

wp_redirect( home_url('/questions-listing/') ); 
exit;

}

get_header();

如果用户已登录,他们看不到此索引页面,他们将被重定向到上述页面。

它工作正常,但只在桌面上。在手机上,我收到 ERR_TOO_MANY_REDIRECTS 错误。

到目前为止我尝试了什么:

  • 浏览器中的空缓存和 cookie
  • 在不同的浏览器上试过
  • 检查 WordPress 常规设置中的 URL 是否有任何差异

以防万一,这也是我的 .htaccess 文件的内容

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

感谢任何帮助!

【问题讨论】:

    标签: php wordpress redirect


    【解决方案1】:

    我建议在你的functions.php中通过函数添加代码。

    function redirect_function() {
        if( is_user_logged_in() ) {
    
        wp_redirect( home_url('/questions-listing/') ); 
        exit;
    
        }
    }
    add_action('init', 'redirect_function');
    

    【讨论】:

      【解决方案2】:

      我不确定为什么会这样。但是我曾经发生过这种情况,并通过明确指定在移动设备上做什么来解决。以下内容可能对您有用:

      if( is_user_logged_in() ) {
          if(wp_is_mobile()){
              wp_redirect( esc_url(home_url('/questions-listing/')) ); 
              exit;
      
           }
          else{
              wp_redirect( esc_url(home_url('/questions-listing/')) ); 
              exit;
           }
      }
      
      get_header();
      

      【讨论】:

        猜你喜欢
        • 2022-01-02
        • 1970-01-01
        • 2011-12-29
        • 2014-05-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-13
        • 2019-08-10
        相关资源
        最近更新 更多