Deano Deano - 1 year ago 145
Linux Question

http to https apache redirection

Environment Centos with apache

Trying to setup automatic redirection from http to https

From --- To --->

I have tried adding the following to my httpd.conf but it didn't work

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

Any ideas?

Answer Source

I have actually followed this example and it worked for me :)

NameVirtualHost *:80
<VirtualHost *:80>
   DocumentRoot /usr/local/apache2/htdocs 
   Redirect permanent /

<VirtualHost _default_:443>
  DocumentRoot /usr/local/apache2/htdocs
  SSLEngine On
 # etc...

Then do:

/etc/init.d/httpd restart

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download