redirect http to https with .htaccess (Apache)


I have a domain:

When a user arrives at this root sub-domain URL it gets 301 redirected by the index

Open in new window

    header( 'Location:' ) ;

Open in new window

What I'm trying to do is if the user types in:

then it should be a 301 forward to:

I found this page on stackexchange:

So I tried this but it doesn't work:
RewriteCond %{HTTPS} !ON
RewriteCond ${REQUEST_URI} ^index.php
RewriteRule ^(.*) [R=301, L]

Open in new window

How can I get it to do a 301 redirect to

when the user goes to the insecure

Thank you and Father God bless<><,
Victor KimuraSEO, Web DeveloperAsked:
Who is Participating?
Victor KimuraSEO, Web DeveloperAuthor Commented:
I figured this out.

What ended up working is I added an external vhost.conf by adding the lines with in the VirtualHost container for of the httpd.conf file. My httpd.conf is located at:
/usr/local/apache/conf/httpd.conf (this is Centos 5.6 with WHM 11.4). May be different for you.

You can use: find / -name 'httpd.conf' to find out yours.

Include "/usr/local/apache/conf/userdata/std/2_2/myultrat/*.conf" (this is the default. * = vhost)
Include "/usr/local/apache/conf/userdata/std/2_2/myultrat/*.conf" (this overrides the default vhost.conf in the preceding line)

Open in new window

Victor KimuraSEO, Web DeveloperAuthor Commented:
By Father's grace, I figured it out. :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.