我有一个具有以下结构的网站:
/public_html
/main site content (html content mostly)
/.htaccess (1)
/secret (dir)
/wp (dir)
/a wordpress install
/.htaccess (2)
/secret/wp/ 旨在成为迁移到 WordPress 解决方案的开发站点。这是我在新网站上工作的地方。
当我尝试查看新站点时,根 .htaccess 导致出现 403 Forbidden 错误。我知道这一点,因为从服务器删除它可以解决问题。
问题是,它正在为我进行一些我需要的重要文件扩展名重写,否则我的主站点就会崩溃。
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 .* $0.html
# browser requests html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.html
RewriteRule ^/?(.*)\.html$ /$1 [L,R=301]
# check to see if the request is for a html file:
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^/?(.*)$ /$1.html [L]
</IfModule>
Redirect 301 /shop.html https://mydomain.myshopify.com/
添加“RewriteRule ^/secret/wp/ - [L]”行是寻找此问题解决方案的结果,但它似乎没有做任何事情。
我的其他 .htaccess 似乎根本没有触发。为了清楚起见,我将发布它:
.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).*) $1 [L]
RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
找到答案了。我花了一周的时间挖掘和测试我能找到的每个可能的论坛,但最终(删除整个 wp 安装并重新安装到一个干净的目录后),我找到了解决所有问题的最简单的答案:
我必须编辑我的 .htaccess 文件以允许“index.php”作为有效的 默认索引页。
我的域顶级的 .htaccess 文件只有这一行: 目录索引index.html
我只需将其更改为 DirectoryIndex index.html index.php
然后一切正常。
感谢您的回答。我在尝试子目录博客时遇到了同样的问题。第一次使用 word press,一切似乎都正确,我的网络主机文档没有这个答案。
我收到 403,MyWebsite/blog 文件夹中包含 word press。 正如OP所述,MyWebsite htaccess 文件是问题所在。 DirectoryIndex index.html index.php 必须添加 index.php 才能正常工作!