在子目录上安装 wordpress 时出现 403 错误

403 error on wordpress install on subdirectory

我的网站结构如下:

/public_html
    /main site content (html content mostly)
    /.htaccess (1)
    /secret (dir)
        /wp (dir)
            /a wordpress install
            /.htaccess (2)

/secret/wp/ 旨在成为迁移到 wordpress 解决方案的开发站点。这是我在新网站上工作的地方。

当我尝试查看新站点时,root .htaccess 导致 403 禁止访问错误。我知道这是因为从服务器中删除它可以解决问题。

问题是,它正在为我重写一些我需要的重要文件扩展名,否则我的主站点就会中断。

htaccess (1)

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>

DirectoryIndex index.html

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteRule ^(wp-admin)($|/) - [L] # You don't want to mess with WordPress 
 RewriteRule ^/secret/wp/ - [L]
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME}\.html -f
 RewriteRule .* [=11=].html

 # browser requests html
 RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.html
 RewriteRule ^/?(.*)\.html$ / [L,R=301]

 # check to see if the request is for a html file:
 RewriteCond %{REQUEST_FILENAME}\.html -f
 RewriteRule ^/?(.*)$ /.html [L]
</IfModule>

Redirect 301 /shop.html https://mydomain.myshopify.com/

添加行 "RewriteRule ^/secret/wp/ - [L]" 是搜索此问题的解决方案的结果,但似乎没有任何作用。

我的另一个 .htaccess 似乎根本没有触发。为了清楚起见,我将post它:

.htaccess (2)

# BEGIN WordPress
<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteBase /secret/wp/

    RewriteRule ^index\.php$ - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule . /secret/wp/index.php [L]

    # Fix 403 errors on existing directories; WordPress overrides.
        RewriteCond %{REQUEST_URI} ^/secret/wp/
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule . /index.php [L]

</IfModule>
# END WordPress

我不知所措。我不能只删除 .htaccess 文件,否则整个站点都会中断,但我似乎无法弄清楚如何停止 403 错误。我很确定这是因为重写规则,但它似乎并没有像预期的那样停止目录。

如有任何帮助,我们将不胜感激。

我想你可以在你的 .htaccess 中试试这个

RewriteCond %{REQUEST_FILENAME} -f [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^ - [L]

RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*)  [L]

RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$  [L]

RewriteRule . index.php [L]

找到答案了。我花了一周的时间在我能找到的每个可能的论坛上进行挖掘和测试,但最终(在删除整个 wp 安装并重新安装到一个干净的目录之后),我找到了解决所有问题的最简单的答案:

I had to edit my .htaccess file to allow "index.php" as a valid default index page.

My .htaccess file for the top level of my domain only had this line: DirectoryIndex index.html

I just had to change it to DirectoryIndex index.html index.php

And then everything worked.