【问题标题】:Redirect address with folder structure to https?将具有文件夹结构的地址重定向到 https?
【发布时间】:2013-03-11 20:39:44
【问题描述】:

我想确保我的所有流量都在 ssl 上,即使他们键入 http。但我也希望它传递文件夹,所以 mod_rewrite 仍然可以工作。我尝试了这个糟糕的例子,但它不起作用。基本上我如果他们输入http://mydomain.com/apage,它将重定向到https://mydomain.com/apage

服务器:Apache2、LAMP 堆栈。

.htaccess

RewriteEngine on

RewriteCond %{HTTPS} !=on
RewriteRule ^(/) https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]

我愿意为 Apache 调整虚拟主机文件,但我以前从未见过这样做过。这是我第一次进入 SSL 托管。

【问题讨论】:

  • “如果他们输入mydomain.com/apage,它将重定向到mydomain.com/apage”。这不正是你想要的吗?
  • 仔细阅读该地址并牢记这篇文章的整个上下文...
  • 我不明白。您想从 http 更改为 https。其他一切都应保持不变。
  • 是的……这就是我想做的事

标签: apache .htaccess


【解决方案1】:

只需将http 替换为https

RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

【讨论】:

    【解决方案2】:

    如果您可以访问 httpd.conf,我建议不要使用 mod_rewrite 或 htaccess。 如果您想强制所有用户使用 https(一个好主意),您可以在 httpd.conf 中添加类似这样的内容:

        ServerName SSL.EXAMPLE.COM
        CustomLog /var/log/httpd/EXAMPLE.access_log combined
        ErrorLog /var/log/httpd/EXAMPLE.error_log
    
        Redirect / https://ssl.example.com/ 
    

    虚拟主机>

    ServerName ssl.example.com
    DocumentRoot /var/www/html
    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite HIGH:MEDIUM
    .
    .
    . 
    

    虚拟主机>

    #If all else fails, this will ensure nothing can get in without being encrypted.
    SSLRequireSSL 
    

    目录>

    【讨论】:

    • 我会,但这不会通过您的查询或文件夹。在这种情况下,它是一个 API,虽然它不是一个好习惯,但我需要它来强制它。有什么办法让它也传递文件夹吗?
    猜你喜欢
    • 2012-03-27
    • 1970-01-01
    • 2011-06-13
    • 2015-09-15
    • 2013-04-01
    • 2016-01-09
    • 2017-06-01
    • 2015-04-12
    • 2016-07-30
    相关资源
    最近更新 更多