Synology个人网站HTACCESS导致403个错误
- 具有DSM 7.1.X的Synology Server(最近从DSM 6.X更新并降低了DSM 6.X,Synology不建议
- 使用HTTP后端服务器启用了网站:Apache HTTP Server 2.4和PHP: PHP 8.0
- 个人网站,具有这些设置HTTP后端服务器:Apache HTTP服务器2.4和 PHP:PHP 7.4
- 个人网站使用WordPress 5.x或6.x,需要.htaccess文件
问题:个人网站.htaccess in/home/homes/user/www文件夹导致403错误
可以删除.htacccess .htacccess要停止403错误,但是个人网站使用需要.htaccess的WordPress - 不能只是删除此文件,因为某些WordPress操作会重新创建.htaccess文件(例如更改设置>永久链接) 新创建的测试用户案例:TMP
- Homes/tmp/www文件夹的“用户”组具有775个权限
- 家庭/tmp/www/.htaccess的所有者,其所有者为“用户名”,并且具有770个权限的“用户”组
- /tmp/tmp/www/www/ wp-config.php拥有“用户名”和一组“用户”的所有者,
- 即使有权限,也 有770个权限在房屋/TMP/www中的所有文件中的777中,
- 在删除.htaccess并创建/发布新页面之后,仍存在403错误,而403错误仍存在。查看新页面会导致404错误。
默认值.htaccess行
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /~username/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~username/index.php [L]
</IfModule>
,即使.htaccess根本没有代码行,也存在403个错误。因此,不论内容如何导致403误差。
有人有解决这个问题的想法吗?
- Synology Server with DSM 7.1.x (recently updated from DSM 6.x and downgrading back down to DSM 6.x is not recommended by Synology)
- Webstation Enabled with HTTP back-end server: Apache HTTP Server 2.4 and PHP:
PHP 8.0 - Personal Websites with these settings HTTP back-end server: Apache HTTP Server 2.4 and
PHP: PHP 7.4 - Personal Websites use WordPress 5.x or 6.x which require a .htaccess file
Problem: Personal Website .htaccess in /homes/user/www folders causes the 403 error
Could delete .htaccess to stop 403 error but Personal Websites use WordPress which requires .htaccess - cannot just delete this file because some WordPress actions recreates the .htaccess file (such as changing Settings > Permalinks)
Newly created test user case: tmp
- homes/tmp/www folder has "users" group with 775 permissions
- homes/tmp/www/.htaccess has owner of "username" and group of "users" with 770 permissions
- homes/tmp/www/wp-config.php has owner of "username" and group of "users" with 770 permissions
- Even with permissions of 777 for ALL files in homes/tmp/www, the 403 error still exists with .htaccess
- After deleting the .htaccess and creating/publishing a new page, viewing the new page results in a 404 error.
Default .htaccess lines
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /~username/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~username/index.php [L]
</IfModule>
Even if .htaccess has no lines of code at all, the 403 error exists. So just the existence of the .htaccess file regardless of content causes a 403 error.
Anyone have ideas to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我偶然发现的解决方案:
为Apache2.x编辑httpd2x.conf(为个人网站选择的哪个)
添加以下代码,
我尝试了很多东西,我认为以上是技巧。
Solution I stumbled upon:
Edit the httpd2x.conf for Apache2.x (whichever is chosen for Personal Websites)
Add the following code
I tried a bunch of stuff and I think the above was the trick.
看起来您正在使用 apache pache per-user per-user web目录?如果是这种情况,则
/〜用户名
不是物理目录(对您的用户目录的“别名”),并且您的文档root有效/〜用户名/
(哪个真的与根层的URL路径混在一起)。在这种情况下,您的
.htaccess
应该是这样的:请注意,我已经完全删除了
rewriteBase
完全指令。但是,如果这是WordPress代码块的一部分(即内部
#begin wordpress
...#end wordpress
)注释标记,那么WordPress将尝试覆盖您的更改,除非您采取其他步骤来防止这种情况。It looks like you are using Apache per-user web directories? If that's the case then
/~username
is not a physical directory (it's an "alias" to your user directory) and your document root is effectively/~username/
(which really messes with root-relative URL-paths).In which case, your
.htaccess
should be like this instead:Note that I've removed the
RewriteBase
directive altogether.However, if this is part of the WordPress code block (ie. inside
# BEGIN WordPress
...# END WordPress
) comment markers then WordPress is going to try and overwrite your changes unless you take additional steps to prevent this.