# How to redirect to HTTPS using SLIM 3

**URL:** <https://discourse.slimframework.com/t/how-to-redirect-to-https-using-slim-3/1602>\
**Category:** Questions\
**Created:** [June 21, 2017, 7:20pm UTC](https://discourse.slimframework.com/t/how-to-redirect-to-https-using-slim-3/1602 "2017-06-21T19:20:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohistanboli](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/mohistanboli/32/411_2.png) [@mohistanboli](https://discourse.slimframework.com/u/mohistanboli)\
**Post date:** [June 21, 2017, 7:20pm UTC](https://discourse.slimframework.com/t/how-to-redirect-to-https-using-slim-3/1602/1 "2017-06-21T19:20:09Z")

</div>

Hello guys I am using slim 3 framework and I use the default htaccess file on slim documentation so when a request come to my server it will be passed to index.php which will make use of the router to render a specific view

now my question is how to make use of my https with keep using this method

I found this in stackoverflow

> RewriteEngine On  
> RewriteCond %{HTTPS} !on  
> RewriteRule (.\*) https://%{HTTP\_HOST}%{REQUEST\_URI}

but if I use it then the router won’t work properly cause this will disturb it

please help

---

<div class="post-metadata">

**Author:** ![damianopetrungaro](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/damianopetrungaro/32/236_2.png) [@damianopetrungaro](https://discourse.slimframework.com/u/damianopetrungaro)\
**Post date:** [June 22, 2017, 9:41am UTC](https://discourse.slimframework.com/t/how-to-redirect-to-https-using-slim-3/1602/2 "2017-06-22T09:41:00Z")

</div>

Is not a “slim” topic, anyway you can use an .htaccess for archive it:

let me know if is not working 😃

```
### Activate the rewrite rule engine
RewriteEngine on

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
```

---

<div class="post-metadata">

**Author:** ![mohistanboli](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/mohistanboli/32/411_2.png) [@mohistanboli](https://discourse.slimframework.com/u/mohistanboli)\
**Post date:** [June 22, 2017, 6:19pm UTC](https://discourse.slimframework.com/t/how-to-redirect-to-https-using-slim-3/1602/3 "2017-06-22T18:19:50Z")

</div>

Yes I know it could be accomplished using an htaccess file the problem is I already have an htaccess file that contains the following

> Options -Indexes  
> RewriteEngine On  
> RewriteCond %{REQUEST\_FILENAME} !-f  
> RewriteCond %{REQUEST\_FILENAME} !-d  
> RewriteRule ^ index.php [QSA,L]

This htaccess file will pass any url to index.php file so I can use my slim router how to keep using the slim router along with https this is my question.

Hope you get what I mean , thanks in advance.

---

<div class="post-metadata">

**Author:** ![damianopetrungaro](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/damianopetrungaro/32/236_2.png) [@damianopetrungaro](https://discourse.slimframework.com/u/damianopetrungaro)\
**Post date:** [June 22, 2017, 8:35pm UTC](https://discourse.slimframework.com/t/how-to-redirect-to-https-using-slim-3/1602/4 "2017-06-22T20:35:20Z")

</div>

But it doesn’t have any effect using https or https on slim router.  
So i don’t understand what’s your problem.

---

<div class="post-metadata">

**Author:** ![mohistanboli](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/mohistanboli/32/411_2.png) [@mohistanboli](https://discourse.slimframework.com/u/mohistanboli)\
**Post date:** [June 23, 2017, 9:08pm UTC](https://discourse.slimframework.com/t/how-to-redirect-to-https-using-slim-3/1602/5 "2017-06-23T21:08:21Z")

</div>

yes I know this to be more specific I don’t know what these line of code does I used the htaccess file on slim docs but I don’t know exactly how it works.

what I mean about it will disturb my router if it type this in my url myurl/about-us the about us will be passed to index.php which will have a similar route to redirect the user for in the file you give me you removed the

> RewriteRule ^ index.php [QSA,L]

so how would the request be passed to the index.php then
