访问 web htaccess 时出错 AH01797:客户端被服务器配置拒绝
error accessing web htaccess AH01797: client denied by server configuration
我在外部打开我的网站时遇到错误。
我收到此错误:
内部服务器错误
服务器遇到内部错误或配置错误,无法完成您的请求。
如果我删除我的 .htaccess,它不会给我错误,但会显示 /htdocs 的路径并且我已经配置了一个子文件夹。
如果我打开 localhost:80 它会正确重定向到子文件夹 htdocs/folder-name
问题是当我通过 www.domain.com 外部打开它时。
这是我的 .htaccess。
路径:C:\Apache24\htdocs.htaccess
内容:
#DON'T SHOW DIRECTORY LISTINGS
Options -Indexes
#FOLLOW SYMBOLIC LINKS
Options +FollowSymLinks
#SET DEFAULT HANDLER
DirectoryIndex index.html index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^DOMAIN.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.DOMAIN.com$
RewriteCond %{REQUEST_URI} !FOLDER/
RewriteRule (.*) /FOLDER/ [L]
#ERROR 404 PAGE
ErrorDocument 404 /404.html
APACHE 日志:
client denied by server configuration: C:/Apache24/htdocs/WEBSITE-XX/
[AH01797: client denied by server configuration: C:/Apache24/error/HTTP_FORBIDDEN.html.var
AH01797: client denied by server configuration: C:/Apache24/htdocs/WEBSITE-XX/favicon.ico, referer: https://www.example.com/
AH01797: client denied by server configuration: C:/Apache24/error/HTTP_FORBIDDEN.html.var, referer: https://www.example.com/
** 重写模块处于活动状态且路径正确**
httpd.conf 虚拟主机代码
编辑
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot C:\Apache24\htdocs\example
ErrorLog C:\Apache24\logs\error.log
CustomLog C:\Apache24\logs\access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot C:\Apache24\htdocs\example
ErrorLog C:\Apache24\logs\error.log
CustomLog C:\Apache24\logs\access.log combined
SSLEngine on
SSLCertificateFile C:\Apache24\conf\certificate.crt
SSLCertificateKeyFile C:\Apache24\conf\private.key
</VirtualHost>
**** 用新的 HTTPD.CONF 编辑 ****
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot C:\Apache24\htdocs\example
ErrorLog C:\Apache24\logs\error.log
CustomLog C:\Apache24\logs\access.log combined
<Directory C:\Apache24\htdocs\example>
# Requried for mod_rewrite (and disable Indexes / MultiViews)
Options FollowSymLinks
# Allow access
Require all granted
# Enabled .htaccess overrides
AllowOverride All
</Directory>
Redirect 301 / https://example.com/
# RewriteEngine on
# RewriteCond %{SERVER_NAME} =example.com [OR]
# RewriteCond %{SERVER_NAME} =www.example.com
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot C:\Apache24\htdocs\example
ErrorLog C:\Apache24\logs\error.log
CustomLog C:\Apache24\logs\access.log combined
<Directory C:\Apache24\htdocs\example>
# Requried for mod_rewrite (and disable Indexes / MultiViews)
Options FollowSymLinks
# Allow access
Require all granted
# Enabled .htaccess overrides
AllowOverride All
</Directory>
SSLEngine on
SSLCertificateFile C:\Apache24\conf\certificate.crt
SSLCertificateKeyFile C:\Apache24\conf\private.key
</VirtualHost>
````
<VirtualHost *:80>
:
DocumentRoot C:\Apache24\htdocs\example
:
<VirtualHost *:443>
:
DocumentRoot C:\Apache24\htdocs\Mymxtools
令人困惑的是,您为两个 VirtualHosts 定义了不同的 DocumentRoot
。 (也许这是您的示例中的错误?)尽管您将所有内容都重定向到 HTTPS,所以这并不重要,因为它发生了。
但是,您没有“允许”访问文件系统的这一部分或启用 .htaccess
覆盖。
您需要在 <VirtualHost *:443>
容器中使用类似以下内容来授予访问权限并启用 .htaccess
覆盖。
<Directory C:\Apache24\htdocs\Mymxtools>
# Requried for mod_rewrite (and disable Indexes / MultiViews)
Options FollowSymLinks
# Allow access
Require all granted
# Enabled .htaccess overrides
AllowOverride All
</Directory>
旁白:
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
要在 <VirtualHost *:80>
容器中将所有内容从 HTTP 重定向到 HTTPS,您不需要这个“复杂的”mod_rewrite 规则。一个更简单的 mod_alias Redirect
就足够了(也是首选)。
例如,改用以下内容:
Redirect 301 / https://example.com/
您应该在此阶段规范化主机名。您之前的 mod_rewrite 规则将保留主机名,即。 www 或 non-www.
我在外部打开我的网站时遇到错误。 我收到此错误: 内部服务器错误 服务器遇到内部错误或配置错误,无法完成您的请求。
如果我删除我的 .htaccess,它不会给我错误,但会显示 /htdocs 的路径并且我已经配置了一个子文件夹。
如果我打开 localhost:80 它会正确重定向到子文件夹 htdocs/folder-name 问题是当我通过 www.domain.com 外部打开它时。
这是我的 .htaccess。 路径:C:\Apache24\htdocs.htaccess 内容:
#DON'T SHOW DIRECTORY LISTINGS
Options -Indexes
#FOLLOW SYMBOLIC LINKS
Options +FollowSymLinks
#SET DEFAULT HANDLER
DirectoryIndex index.html index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^DOMAIN.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.DOMAIN.com$
RewriteCond %{REQUEST_URI} !FOLDER/
RewriteRule (.*) /FOLDER/ [L]
#ERROR 404 PAGE
ErrorDocument 404 /404.html
APACHE 日志:
client denied by server configuration: C:/Apache24/htdocs/WEBSITE-XX/
[AH01797: client denied by server configuration: C:/Apache24/error/HTTP_FORBIDDEN.html.var
AH01797: client denied by server configuration: C:/Apache24/htdocs/WEBSITE-XX/favicon.ico, referer: https://www.example.com/
AH01797: client denied by server configuration: C:/Apache24/error/HTTP_FORBIDDEN.html.var, referer: https://www.example.com/
** 重写模块处于活动状态且路径正确**
httpd.conf 虚拟主机代码
编辑
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot C:\Apache24\htdocs\example
ErrorLog C:\Apache24\logs\error.log
CustomLog C:\Apache24\logs\access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot C:\Apache24\htdocs\example
ErrorLog C:\Apache24\logs\error.log
CustomLog C:\Apache24\logs\access.log combined
SSLEngine on
SSLCertificateFile C:\Apache24\conf\certificate.crt
SSLCertificateKeyFile C:\Apache24\conf\private.key
</VirtualHost>
**** 用新的 HTTPD.CONF 编辑 ****
<VirtualHost *:80>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot C:\Apache24\htdocs\example
ErrorLog C:\Apache24\logs\error.log
CustomLog C:\Apache24\logs\access.log combined
<Directory C:\Apache24\htdocs\example>
# Requried for mod_rewrite (and disable Indexes / MultiViews)
Options FollowSymLinks
# Allow access
Require all granted
# Enabled .htaccess overrides
AllowOverride All
</Directory>
Redirect 301 / https://example.com/
# RewriteEngine on
# RewriteCond %{SERVER_NAME} =example.com [OR]
# RewriteCond %{SERVER_NAME} =www.example.com
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot C:\Apache24\htdocs\example
ErrorLog C:\Apache24\logs\error.log
CustomLog C:\Apache24\logs\access.log combined
<Directory C:\Apache24\htdocs\example>
# Requried for mod_rewrite (and disable Indexes / MultiViews)
Options FollowSymLinks
# Allow access
Require all granted
# Enabled .htaccess overrides
AllowOverride All
</Directory>
SSLEngine on
SSLCertificateFile C:\Apache24\conf\certificate.crt
SSLCertificateKeyFile C:\Apache24\conf\private.key
</VirtualHost>
````
<VirtualHost *:80> : DocumentRoot C:\Apache24\htdocs\example : <VirtualHost *:443> : DocumentRoot C:\Apache24\htdocs\Mymxtools
令人困惑的是,您为两个 VirtualHosts 定义了不同的 DocumentRoot
。 (也许这是您的示例中的错误?)尽管您将所有内容都重定向到 HTTPS,所以这并不重要,因为它发生了。
但是,您没有“允许”访问文件系统的这一部分或启用 .htaccess
覆盖。
您需要在 <VirtualHost *:443>
容器中使用类似以下内容来授予访问权限并启用 .htaccess
覆盖。
<Directory C:\Apache24\htdocs\Mymxtools>
# Requried for mod_rewrite (and disable Indexes / MultiViews)
Options FollowSymLinks
# Allow access
Require all granted
# Enabled .htaccess overrides
AllowOverride All
</Directory>
旁白:
RewriteEngine on RewriteCond %{SERVER_NAME} =example.com [OR] RewriteCond %{SERVER_NAME} =www.example.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
要在 <VirtualHost *:80>
容器中将所有内容从 HTTP 重定向到 HTTPS,您不需要这个“复杂的”mod_rewrite 规则。一个更简单的 mod_alias Redirect
就足够了(也是首选)。
例如,改用以下内容:
Redirect 301 / https://example.com/
您应该在此阶段规范化主机名。您之前的 mod_rewrite 规则将保留主机名,即。 www 或 non-www.