Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让apache在http和https之间自动切换_Apache_Redirect_Https_Virtualhost - Fatal编程技术网

如何让apache在http和https之间自动切换

如何让apache在http和https之间自动切换,apache,redirect,https,virtualhost,Apache,Redirect,Https,Virtualhost,我负责运行一些常规网站和一些SSL网站的Apache web服务器。所有这些网站都是供公司内部使用的。所有网站都使用VirtualHost指令。 所以我有 - http://siteA.mycompany - http://siteB.mycompany - http://siteC.mycompany - https://siteD.mycompany - https://siteE.mycompany 所有这些都运行良好且顺利,但一些用户向我抱怨,他们访问这些网站时遇到问题,因为有时他们必

我负责运行一些常规网站和一些SSL网站的Apache web服务器。所有这些网站都是供公司内部使用的。所有网站都使用VirtualHost指令。 所以我有

- http://siteA.mycompany
- http://siteB.mycompany
- http://siteC.mycompany
- https://siteD.mycompany
- https://siteE.mycompany
所有这些都运行良好且顺利,但一些用户向我抱怨,他们访问这些网站时遇到问题,因为有时他们必须键入http,有时他们必须键入https。。。(管理员的工作有时很辛苦)

我正在寻找一种解决这项工作的方法:如果使用http协议的请求到达定义为使用https的网站,则必须重定向请求。要执行的相同工作相反(https到http)

另一种解释我在寻找什么的方式:

* user request http://siteD.mycompany
* but website is define as using https protocol
* user's web browser change his request to https://siteD.mycompany
* user is no more bothered anymore by the bad protocol problem
做这项工作有什么建议/好的做法吗?
由于有很多网站都担心这个“问题”,所以解决方案可能是通用的。

请参阅这篇Wiki文章
您需要为每个虚拟主机配置使用这些规则。考虑
https://siteD.mycompany
,如果访问了
http
,您需要以下重写规则将用户重定向到站点的
https
版本。

<VirtualHost *:80 *:443>
ServerName siteD.mycompany
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{HTTP_HOST}/$1 [R=301,L]
</VirtualHost>

要使这些规则起作用,您必须确保虚拟主机配置同时接受端口80和443上的连接。目前,您可能有严格的端口配置,因为当您访问
https://siteD.mycompany
,404被抛出。
祝你好运

当用户访问
http://siteD.mycompany
?另外,您可以为siteD.mycompany设置VirtualHost配置吗?@slash当用户访问“”时,由于此服务器名未配置,因此它会出错,是“ErrorDocument 404”apache指令捕获的,它会将他发送到自定义错误页面您的答案帮助我。谢谢我制作了
ServerName mysite.mycompany.org:443 ServerAlias mysite.mycompany.org:80 DocumentRoot/data/www/mysite。。。RewriteCond%{HTTPS}上的RewriteEngine=在重写规则时^/?(*)https://%{HTTP_HOST}/$1[R=301,L]这项工作well@tdaget字体很高兴它有帮助!请考虑参加投票。我的名声不会达到最低限度。
<VirtualHost *:80 *:443>
ServerName siteD.mycompany
RewriteEngine on
RewriteCond %{HTTPS} =on
RewriteRule ^/?(.*) http://%{HTTP_HOST}/$1 [R=301,L]
</VirtualHost>