【问题标题】:redirect http to https through httpd.conf通过 httpd.conf 将 http 重定向到 https
【发布时间】:2017-12-24 22:02:16
【问题描述】:

需要把http改成https。

http://myServerName/itf/sheldon/imex/ajax/share_details/v1/CH0012221716/issuer/contact.json **Should change to** https://myServerName//itf/sheldon/imex/ajax/share_details/v1/CH0012221716/issuer/contact.json  

为此,我在 httpd.conf 文件中包含以下内容

*LoadModule rewrite_module modules/mod_rewrite.so
RewriteCond %{HTTPS} off
RewriteEngine On
RewriteRule ^(.*)(\/itf)(\/sheldon\/)(.*)\.(json|JSON)$ https://myServerName/$2$3$4.json [L,R=301,NC]
RewriteRule "^(.*)(\/itf)(\/fqs\/)(.*)\.(json|JSON)(.*)$" https://myServerName/itf/fqs/$4.json$6 [R=301,L,NC]
Include  conf/vhost.conf*

The vhost.conf file have necessary configuration for virtualhost:443 
So I am able to get the result if I use https://myServerName/....,
**but not able to get the result with** http://myServerName/...

【问题讨论】:

    标签: apache mod-rewrite httpd.conf


    【解决方案1】:

    设置您的虚拟主机文件/httpd.conf 以包含行

    <VirtualHost *:80>
      ServerName enter.yoursite.com
      Redirect / https://enter.yoursite.com/
    </VirtualHost>
    
    <VirtualHost *:443>
      ServerName enter.yoursite.com
      ServerAdmin some@email.com
      Insert EVERYTHING else in here (rewrite rules, log file stuff, etc)
    </VirtualHost>
    

    这将强制网站始终重定向到 HTTPS,然后在 HTTPS 下加载您想要的所有配置。

    【讨论】:

      【解决方案2】:

      我找到了解决方案: 要将特定或任何 http 调用更改为 https 调用,请将代码放入

      VirtualHost :80
         ErrorLog /var/log/httpd/error_log
         CustomLog logs/access.log common
         LogLevel info
         RewriteCond %{HTTPS} off
         RewriteEngine On
         RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
         RewriteEngine On
      

      【讨论】:

        猜你喜欢
        • 2013-09-14
        • 2018-12-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-04
        相关资源
        最近更新 更多