user2552725
user2552725

Reputation:

Redirect site from http to https

              I created domain as http://www.example.com/ Now I bought a SSL for it. When I type https://www.example.com in address bar, it show my site in secure https. On other times, it didn't show https on my site.
               Now I want to redirect to https from http. I searched on google. But someone say redirecting from http to https automatically is not a good idea. Someone says, you can redirect it like facebook, gmail. Now I'm confused.
               Now I've more question on redirection,
        1. May I redirect from http to https?
        2. Is it safe or not?
        3. have I face any problems in future for this redirect?
        4. what is the secure way to redirect http to https?
My .htaccess file:

  RewriteEngine On
  RewriteCond %(REQUEST_FILENAME) !-d
  RewriteCond %(REQUEST_FILENAME) !-f
  RewriteCond %(REQUEST_FILENAME) !-l]
  RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

Updated
I add following to my .htaccess. It redirect well and working fine. But now I get new problem. I can't access inseure content in my page. My .htaccess file is:

RewriteEngine On
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %(REQUEST_FILENAME) !-d
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-l
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

It display errors " [blocked] The page at 'https://www.example.com/red-ball-4-game' was loaded over HTTPS, but ran insecure content from 'http://www.sample.net/img/olume.jpg': this content should also be loaded over HTTPS.

"
How to solve this?

Upvotes: 2

Views: 122

Answers (2)

Rikesh
Rikesh

Reputation: 26451

1: May I redirect from http to https?

  • Yes, you can redirect http to https.

2: Is it safe or not?

  • Obviously it's safe, the s in https stands for secure which itself means safe.

3: Have I face any problems in future for this redirect?

  • Make sure all of your url's are now https and there is not mixture of http and https in your site. This will be not an issue if you have a relative urls throught your site.

4: What is the secure way to redirect http to https ?

  • What you mean by secure here ? But you can right rewrite rule in your htaccess file to redirect all of your url from http to https.

Rule:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule . https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Note: I will suggest you to use https only on the required pages. You can read this post for a better idea by what I mean.

Upvotes: 0

anubhava
anubhava

Reputation: 786091

Place this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

RewriteCond %(REQUEST_FILENAME) !-d
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

This will force all pages of your website to always open in https.

Upvotes: 1

Related Questions