Synology个人网站HTACCESS导致403个错误

发布于 2025-02-13 03:02:17 字数 1181 浏览 0 评论 0原文

  • 具有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泅人 2025-02-20 03:02:17

我偶然发现的解决方案:

为Apache2.x编辑httpd2x.conf(为个人网站选择的哪个)

添加以下代码,

UserDir www
<Directory "var/services/homes/*/www">
    Options FollowSymLinks
    AllowOverride All
</Directory>

我尝试了很多东西,我认为以上是技巧。

Solution I stumbled upon:

Edit the httpd2x.conf for Apache2.x (whichever is chosen for Personal Websites)

Add the following code

UserDir www
<Directory "var/services/homes/*/www">
    Options FollowSymLinks
    AllowOverride All
</Directory>

I tried a bunch of stuff and I think the above was the trick.

や三分注定 2025-02-20 03:02:17
 &lt; ifmodule mod_rewrite.c&gt;
重新创新
重写。*  -  [e = http_authorization:%{http:授权}]
rewriteBase /〜用户名 /
重写 ^index \ .php $  -  [l]
重新WritriteCond%{request_filename}!-f
rewriteCond%{request_filename}!-d
重写。 /~username/index.php [l]
&lt;/ifmodule&gt;
 

看起来您正在使用 apache pache per-user per-user web目录?如果是这种情况,则/〜用户名不是物理目录(对您的用户目录的“别名”),并且您的文档root有效/〜用户名/(哪个真的与根层的URL路径混在一起)。

在这种情况下,您的.htaccess应该是这样的:

RewriteEngine On

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

请注意,我已经完全删除了rewriteBase完全指令。

但是,如果这是WordPress代码块的一部分(即内部#begin wordpress ... #end wordpress)注释标记,那么WordPress将尝试覆盖您的更改,除非您采取其他步骤来防止这种情况。

<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>

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:

RewriteEngine On

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文