0

I want to redirect all my visitors to https://example.com

I have found two codes to implement this, Please tell me which one should I use?

First one:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Second One:

RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
  • Do you want to do that for nginx or apache? Your examples are for Apache. For nginx it's documented [here on stackoverflow](https://stackoverflow.com/documentation/nginx/3631/useful-redirects/12493/https-redirect). – Bbak Jan 30 '17 at 09:03
  • @Laph I want for Apache – Nikhil Singh Jan 30 '17 at 20:07
  • Look [here](http://stackoverflow.com/questions/16200501/http-to-https-apache-redirection) or [here](https://www.sslshopper.com/apache-redirect-http-to-https.html) or even in the official [Apache Wiki](https://wiki.apache.org/httpd/RewriteHTTPToHTTPS) – Bbak Jan 30 '17 at 20:46

0 Answers0