简体   繁体   中英

redirect http to https through httpd.conf

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM