【问题标题】:HTTP redirect not redirectingHTTP 重定向不重定向
【发布时间】:2018-01-24 08:50:01
【问题描述】:

按照here的建议,我在Apache配置文件(本例中为default-ssl.conf)中使用了以下代码

<VirtualHost *:80>
    ServerName name.domain.com
    Redirect / https://name.domain.com/
</VirtualHost>

我已经重新启动了 Apache,但……什么也没有。没有错误,没有重定向。 Http 充当 http,https 充当 https。我做错了什么?我的域名不以“www”开头,但我无法想象会有什么不同。

【问题讨论】:

    标签: apache http https ubuntu-server server-configuration


    【解决方案1】:

    不确定这是否有帮助,有时浏览器会尝试清除 DNS 缓存,在 chrome 中您可以转到 chrome://net-internals/#dns 并清除它,或者使用其他浏览器进行测试。

    <VirtualHost *:80>
      DocumentRoot /home/webroot/example.com/htdocs
    
      ServerName example.com
      ServerAlias www.example.com
    
      <Directory /home/webroot/example.com/htdocs>
        FileETag MTime Size
        DirectoryIndex index.php index.html index.htm
        AllowOverride All
        Order allow,deny
        Allow from all
      </Directory>
    
      RewriteEngine on
      Redirect permanent / http://www.example.com/
      RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
    
      ErrorLog /home/webroot/example.com/logs/error_log
      CustomLog /home/webroot/example.com/logs/access_log combined
    </VirtualHost>
    
    <VirtualHost *:80>
      DocumentRoot /home/webroot/example.com/htdocs
    
      ServerName www.example.com
    
      RewriteEngine on
      Redirect permanent / http://www.example.com/
      RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
    
      ErrorLog /home/webroot/example.com/logs/error_log
      CustomLog /home/webroot/example.com/logs/access_log combined
      RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    </VirtualHost>
    

    【讨论】:

    • 这也没有效果(正面或负面)。绝对不是 DNS 缓存问题。似乎 之间的所有内容都被忽略了...
    • 我已经编辑了我的答案看看是否有帮助,也不要忘记重新启动 httpd
    • 感谢您的帮助。我意识到问题出在哪里。 default-ssl.conf 仅用于 ssl 配置,在那个阶段告诉它有关 http 的任何信息都为时已晚。您描述的代码,如果放在 000-default.conf(ubuntu 服务器 14.4)中,但是可以工作。
    • 哦,真可惜,我对 Ubuntu 不太熟悉
    猜你喜欢
    • 2016-11-11
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2019-12-17
    • 1970-01-01
    • 2019-03-05
    • 2019-09-15
    相关资源
    最近更新 更多