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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Victor KimuraSEO, Web DeveloperAuthor Commented:
By Father's grace, I figured it out. :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.