当我分离wp-core和wp-content时,为什么wordpress会重定向?

时间:2014-02-06 作者:JoeNyland

我正在尝试设置Wordpress项目,以便http://www.example.com/ 作为我的网站URL,例如映射到/var/www/vhosts/www.example.com/ 在这里,我想使用以下结构:

/var/www/vhosts/www.example.com/wp-core/
/var/www/vhosts/www.example.com/wp-content/
/var/www/vhosts/www.example.com/wp-config.php
我想wp-core/ 将Wordpress core安装包含为svn:externalwp-contentwp-config.php 存储在我的SVN repo中,包含每个站点的主题、配置等。

下面的文章将解释如何设置上述结构:http://codex.wordpress.org/Installing_WordPress_With_Clean_Subversion_Repositories

然而,我遇到了一个问题,即站点加载正确,从wp-config.php 上面的文件wp-core 然而,正如预期的那样,当我尝试登录时,Wordpress会从http://www.example.com/wp-login.phphttp://www.example.com/wp-login.php/ - 注意尾部斜杠。

这是对中额外行的确认wp-config.php 我为此添加了:

define(\'WP_CONTENT_DIR\', dirname(__FILE__) . \'/wp-content\');
define(\'WP_CONTENT_URL\', \'http://\' . $_SERVER[\'HTTP_HOST\'] . \'/wp-content\' );
以下是中的相关行wp_options 在my DB中:

SELECT option_name,option_value FROM wp_options WHERE option_name = \'home\';
home,http://www.example.com

SELECT option_name,option_value FROM wp_options WHERE option_name = \'site url\';
siteurl,http://www.example.com
这是我的。htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
    # Hey-ho let\'s go!
    RewriteEngine On
    # Base is the URL path of the home directory
    RewriteBase /
    # Base goes to WordPress
    RewriteRule ^$ /wp-core/index.php [L]
    # Skip real files and directories
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Otherwise send it to WordPress
    RewriteRule .* /wp-core/index.php [L]
</IfModule>
# END WordPress
用Chrome追踪,我可以看到HTTP 301 从正确的地址到带有尾部斜杠的地址由服务器返回,因此它将指向.htaccess 然而,以下摘录的第一行与此有些矛盾:

127.0.0.1 - - [06/Feb/2014:21:02:59 +0000] [www.example.com/sid#7ffb79860180][rid#7ffb7b8020a0/initial] (2) init rewrite engine with requested uri /wp-login.php/
127.0.0.1 - - [06/Feb/2014:21:02:59 +0000] [www.example.com/sid#7ffb79860180][rid#7ffb7b8020a0/initial] (1) pass through /wp-login.php/
127.0.0.1 - - [06/Feb/2014:21:02:59 +0000] [www.example.com/sid#7ffb79860180][rid#7ffb7b8020a0/initial] (3) [perdir /Users/joe/tmp/example.com/trunk-new/] add path info postfix: /Users/joe/tmp/example.com/trunk-new/wp-login.php -> /Users/joe/tmp/example.com/trunk-new/wp-login.php/
127.0.0.1 - - [06/Feb/2014:21:02:59 +0000] [www.example.com/sid#7ffb79860180][rid#7ffb7b8020a0/initial] (3) [perdir /Users/joe/tmp/example.com/trunk-new/] strip per-dir prefix: /Users/joe/tmp/example.com/trunk-new/wp-login.php/ -> wp-login.php/
127.0.0.1 - - [06/Feb/2014:21:02:59 +0000] [www.example.com/sid#7ffb79860180][rid#7ffb7b8020a0/initial] (3) [perdir /Users/joe/tmp/example.com/trunk-new/] applying pattern \'^$\' to uri \'wp-login.php/\'
127.0.0.1 - - [06/Feb/2014:21:02:59 +0000] [www.example.com/sid#7ffb79860180][rid#7ffb7b8020a0/initial] (3) [perdir /Users/joe/tmp/example.com/trunk-new/] add path info postfix: /Users/joe/tmp/example.com/trunk-new/wp-login.php -> /Users/joe/tmp/example.com/trunk-new/wp-login.php/
127.0.0.1 - - [06/Feb/2014:21:02:59 +0000] [www.example.com/sid#7ffb79860180][rid#7ffb7b8020a0/initial] (3) [perdir /Users/joe/tmp/example.com/trunk-new/] strip per-dir prefix: /Users/joe/tmp/example.com/trunk-new/wp-login.php/ -> wp-login.php/
127.0.0.1 - - [06/Feb/2014:21:02:59 +0000] [www.example.com/sid#7ffb79860180][rid#7ffb7b8020a0/initial] (3) [perdir /Users/joe/tmp/example.com/trunk-new/] applying pattern \'.*\' to uri \'wp-login.php/\'
127.0.0.1 - - [06/Feb/2014:21:02:59 +0000] [www.example.com/sid#7ffb79860180][rid#7ffb7b8020a0/initial] (2) [perdir /Users/joe/tmp/example.com/trunk-new/] rewrite \'wp-login.php/\' -> \'/wp-core/index.php\'
具体而言:requested uri /wp-login.php/ 指示Apache收到以下请求:/wp-login.php/ 而不是wp-login.phpmod_rewrite 通过请求。

有没有人能给我提供一些建议,让我可以将WP核心文件放在文档根目录中的一个目录中wp-config/ WP核心目录旁边?

2 个回复
最合适的回答,由SO网友:JoeNyland 整理而成

通过使用.htaccess 在以下链接中提供的文件中,我可以再次访问wp登录,而无需重定向到带有尾部斜杠的URL:

http://ottopress.com/2011/creating-a-wordpress-site-using-svn/

SO网友:Seamus Leahy

wp-login.php 是直接加载的实际文件,而不是使用重写规则。如果您查看中的文件列表/var/www/vhosts/www.example.com/, 您可能不会看到wp-login.php 文件但如果你检查一下/var/www/vhosts/www.example.com/wp-core/, 如果我正确理解您的配置,您可能会找到它。这意味着您的登录URL实际上是:http://www.example.com/wp-core/wp-login.php

现在,您当前的设置存在另一个问题。WordPress不知道核心文件所在的URL,因此也不知道站点的管理区域。默认情况下,WordPress对公共端使用相同的URL(home url) 和安装文件夹(site url). 你可以configure this in your wp-config.php file:

define( \'WP_SITEURL\', \'http://example.com/wp-core\' ); // Where the WP core is
define( \'WP_HOME\', \'http://example.com/\' ); // Where the public goes to view your blog

结束