htpasswd 与 htaccess 冲突
当我尝试添加 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
参考 https://httpd.apache.org/docs/2.4/mod /mod_authn_core.html#authtype
AuthType 只能包含在
语句或 .htaccess 文件中。所以你必须指定一个目录,像这样:不允许像你那样拥有它。如果您想以此保护整个网站,可以将
子句设置在与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: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 yourDocumentRoot
value.