Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Redirect all website traffic to https - cPanel or .htaccess

Posted on 2014-01-21
10
Medium Priority
?
654 Views
Last Modified: 2014-01-22
G'day guys,

I've searched for my particular query but everyone had different focus'.

What I have:

cPanel shared hosting, with legitimate SSL Certificate

What I need:

All traffic hitting http://techcare.net.au and http://www.techcare.net.au to be redirected to https://www.techcare.net.au 

I need this to happen at every stage of the journey. For example I host my own support ticket system in a sub folder https://www.techcare.net.au/support/

It needs to redirect any query to www.techcare.net.au/support or to the admin page www.techcare.net.au/support/scp to secure traffic - https://www.techcare.net.au/support or https://www.techcare.net.au/support/scp

Anyone know how to do this?

regards,
Steve
0
Comment
Question by:sjswarts
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39799095
I think this is what you want.  Put it in an '.htaccess' file in your web root.
From http://wiki.apache.org/httpd/RewriteHTTPToHTTPS
RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context

Open in new window

0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 39799344
0
 
LVL 16

Expert Comment

by:hankknight
ID: 39799997
Try this code in your .htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:sjswarts
ID: 39801881
Is that a replacement to what Dave Baldwin gave?

Do I put that in the public_html/.htaccess or do I have to put it in every .htaccess that is on my hosting?
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39801945
Both versions are almost identical.  The one I posted had some helpful text along with the rules.  You only need to put it in the top level .htaccess for that site.  All requests for any pages on that site will use the rules in the top level .htaccess.
0
 

Author Comment

by:sjswarts
ID: 39801955
Thank you for the clarification Dave.

Just one more thing however.

How do I force the use of www ?? So if someone goes to http://techcare.net.au it rightly redirects to https://techcare.net.au now, but how do I force it to actually go to https://www.techcare.net.au

cheers,
Steve

P.S. I do prefer the helpful text, cleared it up a lot.
0
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 39802188
Try this, this is what worked on one of my sites.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.techcare.net.au%{REQUEST_URI} [L,R=301]

Open in new window

0
 

Author Comment

by:sjswarts
ID: 39802259
Brilliant Dave, absolutely brilliant.

Works like a charm so far, thank you very much.

RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteCond %{HTTP_HOST} !^www\.
# This prepends www to any direct entry

RewriteRule ^ https://www.techcare.net.au%{REQUEST_URI} [L,R=301]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context

Open in new window


that's the total package
0
 

Author Closing Comment

by:sjswarts
ID: 39802260
Exactly what I was looking for
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39802263
You're welcome, glad to help.
0

Featured Post

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question