redirect http to https through httpd.conf

谁说我不能喝 提交于 2019-12-02 09:24:53

问题


Need to change http to 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  

To do this I have following in my httpd.conf file

*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/...

回答1:


Set up your virtual host file / httpd.conf to have lines

<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>

This will force the website to always redirect to HTTPS and then load all the configurations you want under HTTPS.




回答2:


I found the solution: To change particular or any http call to https call, put the code in

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


来源:https://stackoverflow.com/questions/45193829/redirect-http-to-https-through-httpd-conf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!