WordPress在子目录的子目录中

时间:2012-05-10 06:42:46

标签: wordpress .htaccess subdirectory

这应该很简单 - 无法弄清楚我哪里出错:

我们在以下位置安装了WordPress:http://example.com/gallery/cms 我希望该网站在http://example.com/gallery

处可见

我将WordPress地址设置为http://example.com/gallery/cms,并将网站地址设置为http://example.com/gallery

我将.htaccess和index.php复制到/ gallery文件夹。 .htaccess包含以下代码:

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

index.php包含以下代码:

define('WP_USE_THEMES', true);
require('./cms/wp-blog-header.php');

主页加载正常,但任何内页都会出现“未找到”错误:http://playstartshere.com/gallery/specs/会产生The requested URL /gallery/specs/ was not found on this server.

我哪里错了?我尝试将index.php更改为:

define('WP_USE_THEMES', true);
require('./gallery/cms/wp-blog-header.php');

但这完全破坏了网站。

编辑:答案

Apache确实配置错误; RewriteEngine未启用。然而,.htaccess也是错误的。纠正.htaccess以获得如上所述的配置:

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

希望能帮助别人。

1 个答案:

答案 0 :(得分:0)

/gallery/specs/符合此规则:

RewriteRule ^index\.php$ - [L]

阻止访问

尝试使用/gallery/.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

没有/前置index.php,apache将在当前目录中搜索

修改

再次采用不同的方法:

将所有wordpress网址设为http://example.com/gallery 将所有wordpress文件放在/ gallery / cms

将一个.htaccess放入/ gallery / cms

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

将第二个.htaccess放入/ gallery(不带index.php)

RewriteEngine On
RewriteCond %{REQUEST_URI} !/gallery/cms
RewriteRule ^(.*)$ /gallery/cms/$1 [L]