通过httpd.conf将http重定向到https

时间:2017-07-19 14:36:24

标签: apache mod-rewrite httpd.conf

需要将http更改为https。

getDataFromWebService(postData: Kpi): EventEmitter<Kpi> {
    const event: EventEmitter<Kpi> = new EventEmitter();
    this.sendPost(myService.API_PATH, postData).subscribe((data) => {
      try {
        if (this.checkError(data)) {
          const parseData: Kpi = Kpi.parse(data);
          event.emit(parseData);
        } else {
          event.emit(new Kpi());
        }
      } catch (ex) {
        this.env.error("Unknown error", "Invalid data received");
        console.log("Exception", ex);
        kpiEvent.emit(new Kpi());
      }
    });
    return event;
  }

要做到这一点,我在 httpd.conf 文件

中有以下内容
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  

2 个答案:

答案 0 :(得分:2)

将虚拟主机文件/ 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下加载您想要的所有配置。

答案 1 :(得分:0)

我找到了解决方案: 要将特定或任何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