htpasswd 与 htaccess 冲突

发布于 2025-01-12 10:30:16 字数 1249 浏览 5 评论 0原文

当我尝试添加 AuthType 时,当我输入密码时,我的网站无法运行。 你知道出了什么问题吗?

我收到错误 500。但是如果没有 AuthType,它就可以工作

AuthType Basic
AuthName "restricted area"
AuthUserFile .htpasswd
require valid-user

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Options All -Indexes -MultiViews

RewriteCond %{DOCUMENT_ROOT}/$1.html -f [NC]
RewriteRule ^(.+?)/?$ $1\.html

RewriteCond %{REQUEST_URI} ^$1/index [NC]
RewriteRule ^ - [L]

RewriteRule ^en/ - [L]
RewriteRule ^pl/ - [L]

RewriteCond %{HTTP:Accept-Language} !^pl [NC]
RewriteCond %{REQUEST_URI} !^/assets [NC]
RewriteCond %{REQUEST_URI} !^/js [NC]
RewriteCond %{REQUEST_URI} !^/lib/sendmail.php [NC]
RewriteCond %{REQUEST_URI} !^/robots.txt [NC]
RewriteCond %{REQUEST_URI} !^/sitemap.xml [NC]
RewriteRule ^ /en%{REQUEST_URI} [L]

RewriteCond %{HTTP:Accept-Language} ^pl [NC]
RewriteCond %{REQUEST_URI} !^/assets [NC]
RewriteCond %{REQUEST_URI} !^/js [NC]
RewriteCond %{REQUEST_URI} !^/lib/sendmail.php [NC]
RewriteCond %{REQUEST_URI} !^/robots.txt [NC]
RewriteCond %{REQUEST_URI} !^/sitemap.xml [NC]
RewriteRule ^ /pl%{REQUEST_URI} [L]

When I try to add AuthType my site does not work when I enter my password.
Do you know what is wrong?

I am getting error 500. But without AuthType it works

AuthType Basic
AuthName "restricted area"
AuthUserFile .htpasswd
require valid-user

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Options All -Indexes -MultiViews

RewriteCond %{DOCUMENT_ROOT}/$1.html -f [NC]
RewriteRule ^(.+?)/?$ $1\.html

RewriteCond %{REQUEST_URI} ^$1/index [NC]
RewriteRule ^ - [L]

RewriteRule ^en/ - [L]
RewriteRule ^pl/ - [L]

RewriteCond %{HTTP:Accept-Language} !^pl [NC]
RewriteCond %{REQUEST_URI} !^/assets [NC]
RewriteCond %{REQUEST_URI} !^/js [NC]
RewriteCond %{REQUEST_URI} !^/lib/sendmail.php [NC]
RewriteCond %{REQUEST_URI} !^/robots.txt [NC]
RewriteCond %{REQUEST_URI} !^/sitemap.xml [NC]
RewriteRule ^ /en%{REQUEST_URI} [L]

RewriteCond %{HTTP:Accept-Language} ^pl [NC]
RewriteCond %{REQUEST_URI} !^/assets [NC]
RewriteCond %{REQUEST_URI} !^/js [NC]
RewriteCond %{REQUEST_URI} !^/lib/sendmail.php [NC]
RewriteCond %{REQUEST_URI} !^/robots.txt [NC]
RewriteCond %{REQUEST_URI} !^/sitemap.xml [NC]
RewriteRule ^ /pl%{REQUEST_URI} [L]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

傾旎 2025-01-19 10:30:16

参考 https://httpd.apache.org/docs/2.4/mod /mod_authn_core.html#authtype

AuthType 只能包含在 语句或 .htaccess 文件中。所以你必须指定一个目录,像这样:

<Directory "/www/htdocs">

    YOUR AUTH CONFIGURATION HERE

</Directory>

不允许像你那样拥有它。如果您想以此保护整个网站,可以将 子句设置在与 DocumentRoot 值相同的目录中。

Reference https://httpd.apache.org/docs/2.4/mod/mod_authn_core.html#authtype

AuthType can only be enclosed in a <Directory> statement, or in a .htaccess file. So you must specify a directory, like this:

<Directory "/www/htdocs">

    YOUR AUTH CONFIGURATION HERE

</Directory>

It is not allowed to have it like you did. If you want to protect your entire site with this, you can setup your <Directory> clause on the same directory as your DocumentRoot value.

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