欢迎转载!转载时请注明出处:http://blog.csdn.net/nfer_zhuang/article/details/50316171
前言
WordPress自带的注册页面比较简陋,BuddyPress插件提供了一个比较丰富的注册页面,但是当我打开页面时却显示了“404 Not Found”(已打开WordPress的注册开关并设置了Buddypress的注册页面),本篇文章就是记录如何排查和解决该问题的。
问题截图
注:我是在WordPress4.3.1版本下进行的测试
排查问题
确认BuddyPress页面设置
通过截图,我们确认设置了使用BuddyPress的注册页面来替换原生页面。
确认页面是否可以直接打开
我们注意在每个设置的右边有一个view的按钮,那么直接点击这个按钮是否可以打开页面呢?
通过截图,我们确认直接打开页面是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 ) {