我目前正在使用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
更多推荐
发布评论