0

I've just got an SSL certificate for my website, but as default when I just write down mywebsite.com the browser brings me to http://mywebsite.com instead of https://mywebsite.com.

Googling I found people saying to redirect from the old URLs to the secure ones, but how can I? Should I check for every single page whether or not my website is on a secure URL?

Furthermore, visiting SSL protected websites and opening their source code, I can't even look at view-source:http://securewebsite.com, because it redirects me to view-source:https://securewebsite.com (it wouldn't do so with a simple redirect to the new URL).

So how can I make every visit to mywebsite.com a visit to the secure website and not the unsecure one?

EDIT: I'm using a register.it domain and hosting it from 000webhost.com

  • 1
    Does this answer your question? [How to redirect all HTTP requests to HTTPS](https://stackoverflow.com/questions/4083221/how-to-redirect-all-http-requests-to-https) – Nico Haase Mar 20 '20 at 08:44
  • Additionally, please don't use irrelevant tags. Your question has completely no connection to PHP or HTML – Nico Haase Mar 20 '20 at 08:44
  • @NicoHaase I thought at making a redirect using `meta refresh` or `header` when I am on an unsecure URL –  Mar 20 '20 at 08:48
  • .....and why not do that if you have already thought about that? – Nico Haase Mar 20 '20 at 08:49
  • @NicoHaase beacuse, as I said, visiting famous secure website I get redirected even looking at the source code, and it wouldn't happen so if I use HTML or PHP redirect –  Mar 20 '20 at 08:51
  • @NicoHaase furthermore, it seems a bit awkward a check to the URL for every single page, so I asked if there was a better way to do so –  Mar 20 '20 at 08:52
  • You should mention what you're using to build and host your website so that people can give you more specific help. – porglezomp Mar 20 '20 at 08:53
  • @porglezomp I'm using a register.it domain and hosting it from 000webhost.com –  Mar 20 '20 at 08:54

1 Answers1

0

You can add below code in you .htaccess file on root.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mywebsite.com/$1 [R,L]
  • It seems to work... Can I ask you what does `%{SERVER_PORT} 80` mean and why `$1` at the end of the URL? –  Mar 20 '20 at 08:57
  • $1 = Because if anyone access subpages with only "HTTP" It will be automatically redirected to "HTTPS" with the same page. – Laxman Prajapati Mar 20 '20 at 09:03
  • Please add some further explanation to your answer by editing - why do you check for any arbritrary port and not for the `%{HTTPS}` flag? – Nico Haase Mar 20 '20 at 09:34