LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   redirect http to https (https://www.linuxquestions.org/questions/linux-server-73/redirect-http-to-https-4175411878/)

Gil@LQ 06-17-2012 02:34 AM

redirect http to https
 
hi,

i configured ssl over http, every thing is fine and working fine, issue is my site is also working with www.mydomain.com it's working with http, so i commented LISTEN 80. so it's not opening with http. now type www.mydomain.com it's not opening, i have to type https manually infront of it. is there any way so that if i type www.mydomain.com, it will automatically redirected to https://www.mydomain.com

i'm using apache on rhel6

thanks in advance.

bathory 06-17-2012 03:52 AM

Hi Gil@LQ,

You can use mod_rewrite for this. You need to go in the http vhost container and add the following:
Code:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Regards

montel 06-18-2012 09:43 AM

I have something similar that is forwarding all traffic to https.

RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]

Good luck :)

Gil@LQ 06-18-2012 03:04 PM

Thank you all for your replies.

it worked thank you very much.

gil@lq


All times are GMT -5. The time now is 09:05 AM.