使用htaccess强制https不适用于使用htpasswd的完整URL(Using htaccess to force https not working for full urls with h

编程入门 行业动态 更新时间:2024-10-14 02:24:47
使用htaccess强制https不适用于使用htpasswd的完整URL(Using htaccess to force https not working for full urls with htpasswd)

我目前正在使用htaccess强制我的apache2服务器上的所有http请求转到https。 https已设置并正常运行。 如果我只使用基本域名(例如: http://mydomain.com : http://mydomain.com ),htaccess重写是有效的,但如果我做了像http://mydomain.com/index.php这样的事情,我会收到401错误说我是未经授权。 我应该提到我的htaccess还使用htpasswd文件将所有内容限制为授权用户。

如果没有使用http - > https的重写,http和https都可以正常使用任何url,因为这个人已登录。如果不是,它会要求他们登录。当我把重写放回去时,它不会问用户登录,只显示401错误页面。

这是我的htaccess文件:

RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] AuthName "Enter Account Info... Or your computer will blow up!!!" AuthType Basic AuthUserFile /<censored>/.htpasswd AuthGroupFile /dev/null require user <censored>

没有那些重写行,一切都运行正常。 对http或https的请求将正常运行,但是对其他任何事情使用重写,那么基本域似乎会破坏某个地方。

我已经尝试了我在网上找到的各种重写规则,都给出了相同的结果,对基本网址工作正常,而不是直接页面链接。

I am currently using htaccess to force all http requests on my apache2 server go to https. https is setup and working properly. The htaccess rewrite is working if i use just the base domain name (ex: http://mydomain.com ), however if i do something like http://mydomain.com/index.php i get a 401 error saying i am not authorized. I should mention my htaccess also restricts all content to authorized users with a htpasswd file.

Without using the rewrite for http -> https, both http and https work properly using any url long as the person is logged in. If they are not it will ask them to log in. When i put the rewrite back in it does not ask to user to log in, and simply shows a 401 error page.

this is my htaccess file:

RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] AuthName "Enter Account Info... Or your computer will blow up!!!" AuthType Basic AuthUserFile /<censored>/.htpasswd AuthGroupFile /dev/null require user <censored>

Without those rewrite lines, everything works fine. a request to either http or https will function normally, but using rewrite for anything other then the base domain seems to break somewhere.

i have tried various rewrite rules i have found around the web, all give same results, working fine for base url, not for direct page links.

最满意答案

我有类似的问题,这对我有用。

在httpd.conf中,在虚拟主机下,确保您同时拥有:

ServerName domain.com

ServerAlias www.domain.com

同时在VirtualHost *:80和VirtualHost *:443

I had similar problem, this is what worked for me.

In your httpd.conf, under virtual hosts, make sure you have both:

ServerName domain.com

ServerAlias www.domain.com

BOTH in VirtualHost *:80 AND VirtualHost *:443

更多推荐

本文发布于:2023-07-30 17:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338870.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不适用于   完整   htpasswd   htaccess   https

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!