【问题标题】:Apache Rewrite: Always use HTTPS (how to add an exception)Apache Rewrite:始终使用 HTTPS(如何添加例外)
【发布时间】:2010-07-14 15:20:18
【问题描述】:

在 mydomain.com 上,我目前将所有 apache conf 文件保存在:

/etc/httpd/conf.d/

在那里我有一个名为 alwaysHttps.conf 的文件,其中包含:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

我有一堆虚拟主机,对于站点上的一个域:myotherdomain.com,我想关闭自动重定向。是否可以设置重定向到 https 的异常,而不必摆脱全局 alwaysHttps.conf?

<VirtualHost *:80> 
    DocumentRoot /home/webadmin/myotherdomain.com/html 
    ServerName myotherdomain.com 
    CustomLog "/home/webadmin/myotherdomain.com/access_log" "combined" 
    ErrorLog "/home/webadmin/myotherdomain.com/error_log" 
    <Directory /home/webadmin/myotherdomain.com/html> 
        Options Includes FollowSymLinks 
        AllowOverride All 
    </Directory> 
</VirtualHost> 

【问题讨论】:

    标签: apache mod-rewrite redirect


    【解决方案1】:
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} !myotherdomain\.com
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA]
    

    【讨论】:

    • 好的——完美!谢谢...这解决了重定向问题,但现在我得到了 404。我的域 conf 文件是:如果我停止修复并将页面加载的 :80 更改为 :443 页面。但是现在的情况,他们没有。有什么快速的想法吗?
    • 你的配置中有NameVirtualHost *:80Listen 80 吗?
    【解决方案2】:

    太棒了!

    在我的 http.conf 我有:

    NameVirtualHost  *:80
    NameVirtualHost  *:443
    
    Listen 8033
    

    监听 8033 的原因是因为我使用 OpenVPN 的功能来双重使用端口 80。一旦我改变了我的

    <VirtualHost *:80>  to 
    <VirtualHost *:8033> 
    

    一切正常。

    奇怪的是为什么我所有的其他虚拟域和 *.conf 文件都可以工作,即使它们有

    <VirtualHost *:80> 
    

    而不是

    <VirtualHost *:8033>. 
    

    知道为什么会这样吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      • 2020-09-03
      • 2011-01-18
      • 2019-07-16
      相关资源
      最近更新 更多