# Redirect HTTP to HTTPS / SSL

**URL:** <https://community.localwp.com/t/redirect-http-to-https-ssl/514>\
**Category:** Support\
**Created:** [January 16, 2017, 5:03pm UTC](https://community.localwp.com/t/redirect-http-to-https-ssl/514 "2017-01-16T17:03:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cliff](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/cliff/32/25260_2.png) [@cliff](https://community.localwp.com/u/cliff)\
**Post date:** [January 16, 2017, 5:03pm UTC](https://community.localwp.com/t/redirect-http-to-https-ssl/514/1 "2017-01-16T17:03:03Z")

</div>

I have a local site that works on HTTPS with nginx.

I tried to add this code:  
# BEGIN Redirect to https / SSL  
RewriteEngine On  
RewriteCond %{HTTPS} !on  
RewriteRule (.\*) https://%{HTTP\_HOST}%{REQUEST\_URI} [R=301,L]  
# END Redirect to https / SSL  
to /…/Documents/Local Sites/app/public/.htaccess

but it’s not redirecting [http://mysite.dev](http://mysite.dev) to [https://mysite.dev](https://mysite.dev)

I switched the webserver to Apache and then the .htaccess rule became effective. How do I setup such a redirect on nginx?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![clay](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/clay/32/8248_2.png) [@clay](https://community.localwp.com/u/clay)\
**Post date:** [January 17, 2017, 3:48pm UTC](https://community.localwp.com/t/redirect-http-to-https-ssl/514/2 "2017-01-17T15:48:15Z")

</div>

Adding this snippet above the `index` line in conf/nginx/site.conf should do the trick 🙂

```auto
if ($http_x_forwarded_proto != "https") {
    rewrite ^(.*)$ https://DOMAIN_GOES_HERE$1 permanent;
}

```

---

<div class="post-metadata">

**Author:** ![raison](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/raison/32/4445_2.png) [@raison](https://community.localwp.com/u/raison)\
**Post date:** [December 13, 2017, 11:10am UTC](https://community.localwp.com/t/redirect-http-to-https-ssl/514/4 "2017-12-13T11:10:42Z")

</div>

Hi Clay

Whats the same requirement but for an Apache server.

I tried this in my .htaccess but get a too many redirects error:

```auto
RewriteCond %{HTTP_HOST} ^site.dev [NC,OR]
RewriteCond %{HTTP_HOST} ^site.dev [NC]
RewriteRule ^(.*)$ https://site.dev/$1 [L,R=301,NC]

```

---

<div class="post-metadata">

**Author:** ![clay](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/clay/32/8248_2.png) [@clay](https://community.localwp.com/u/clay)\
**Post date:** [December 13, 2017, 10:32pm UTC](https://community.localwp.com/t/redirect-http-to-https-ssl/514/5 "2017-12-13T22:32:16Z")

</div>

Hey @raison,

Check out this solution on Stack Overflow: [https://stackoverflow.com/a/36475195](https://stackoverflow.com/a/36475195)

Here’s the `.htaccess` copy and pasted from the solution for convenience:

```auto
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase / 

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

# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

```

---

<div class="post-metadata">

**Author:** ![raison](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/raison/32/4445_2.png) [@raison](https://community.localwp.com/u/raison)\
**Post date:** [December 14, 2017, 12:06am UTC](https://community.localwp.com/t/redirect-http-to-https-ssl/514/6 "2017-12-14T00:06:20Z")

</div>

I get too many redirects with that example too.

Spent much time on this without luck today. Have you managed to get this working with your setup?

Been reading about the move away from .dev domains and how best practice to develop with https, so i suspect it might be good to have this setup like this on local as a default. What do you think?

---

<div class="post-metadata">

**Author:** ![fabiofava](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/fabiofava/32/5240_2.png) [@fabiofava](https://community.localwp.com/u/fabiofava)\
**Post date:** [October 28, 2018, 5:37pm UTC](https://community.localwp.com/t/redirect-http-to-https-ssl/514/7 "2018-10-28T17:37:40Z")

</div>

Hey there! I’m using this for Apache servers for long time

RewriteEngine On  
RewriteCond %{HTTP:X-Forwarded-Proto} !https  
RewriteRule ^(.\*)$ https://%{HTTP\_HOST}/$1 [R=301,L]

Cheers!

---

<div class="post-metadata">

**Author:** ![spartiatis](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/spartiatis/32/8517_2.png) [@spartiatis](https://community.localwp.com/u/spartiatis)\
**Post date:** [October 2, 2019, 2:03am UTC](https://community.localwp.com/t/redirect-http-to-https-ssl/514/8 "2019-10-02T02:03:20Z")

</div>

Hi Clay,

I tried adding your solution in my site.conf file and somehow I forgot to save the file with my URL and now every time click on View Site from the Flywheel Local app, I get my site dev.local to display for an instant and then it redirects to https://domain\_goes\_here.  
I have uninstalled the app and started fresh many times but I can’t seem to get rid of this redirect. If I enter my site’s URL in the browser, it displays my site fine. The redirect only occurs when I click on View Site.  
Any suggestions on clearing this permanent or so it seems redirect?

Thanks very much!

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/community.localwp.com/system/32/1_2.png) [@system](https://community.localwp.com/u/system)\
**Post date:** [August 25, 2020, 6:31pm UTC](https://community.localwp.com/t/redirect-http-to-https-ssl/514/9 "2020-08-25T18:31:24Z")

</div>


