WordPress+BuddyPress注册页面404问题的解决

本文详述了在WordPress4.3.1版本下,使用BuddyPress插件时注册页面出现404错误的排查与解决过程,涉及固定链接设置、Apache的rewrite功能检查、WordPress rewrite规则的分析以及LAMP环境中权限问题的解决。
摘要由CSDN通过智能技术生成

欢迎转载!转载时请注明出处:http://blog.csdn.net/nfer_zhuang/article/details/50316171

前言

WordPress自带的注册页面比较简陋,BuddyPress插件提供了一个比较丰富的注册页面,但是当我打开页面时却显示了“404 Not Found”(已打开WordPress的注册开关并设置了Buddypress的注册页面),本篇文章就是记录如何排查和解决该问题的。

问题截图

问题截图
注:我是在WordPress4.3.1版本下进行的测试

排查问题

确认BuddyPress页面设置

BuddyPress页面设置

通过截图,我们确认设置了使用BuddyPress的注册页面来替换原生页面。

确认页面是否可以直接打开

我们注意在每个设置的右边有一个view的按钮,那么直接点击这个按钮是否可以打开页面呢?
register页面
activate页面

通过截图,我们确认直接打开页面是OK的,至少说明设置是有效的,且页面存在。
但是,我们发现了一个奇怪的地方,就是这两个页面的URL中都带有一个index.php,这是个什么东西呢?看上去完全不符合常理啊。

固定链接

通过查询资料,我们发现这个index.php是根据固定链接中的设置添加到URL中的。
固定链接设置
那为什么WordPress会设置成/index.php/*这种反人类的方式呢?

源码分析

在wp-admin/includes/upgrade.php文件下有下述代码:

    /*
     * The Permalink structures to attempt.
     *
     * The first is designed for mod_rewrite or nginx rewriting.
     *
     * The second is PATHINFO-based permalinks for web server configurations
     * without a true rewrite module enabled.
     */
    $permalink_structures = array(
        '/%year%/%monthnum%/%day%/%postname%/',
        '/index.php/%year%/%monthnum%/%day%/%postname%/'
    );

    foreach ( (array) $permalink_structures as $permalink_structure ) {
        $wp_rewrite->set_permalink_structure( $permalink_structure );

        /*
         * Flush rules with the hard option to force refresh of the web-server's
         * rewrite config file (e.g. .htaccess or web.config).
         */
        $wp_rewrite->flush_rules( true );

        // Test against a real WordPress Post, or if none were created, a random 404 page.
        $test_url = get_permalink( 1 );

        if ( ! $test_url ) {
            $test_url = home_url( '/wordpress-check-for-rewrites/' );
        }

        /*
         * Send a request to the site, and check whether
         * the 'x-pingback' header is returned as expected.
         *
         * Uses wp_remote_get() instead of wp_remote_head() because web servers
         * can block head requests.
         */
        $response          = wp_remote_get( $test_url, array( 'timeout' => 5 ) );
        $x_pingback_header = wp_remote_retrieve_header( $response, 'x-pingback' );
        $pretty_permalinks = $x_pingback_header && $x_pingback_header === get_bloginfo( 'pingback_url' );

        if ( $pretty_permalinks ) {
            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值