0

I am using Heroku php with SSL on. Everything is setup and https works perfectly. My domain hosted in Godaddy. Heroku as apache web server. but http://mysite.com, www.mysite.com will not redirect to https://www.mysite.com which is what i want.

I had changed the .htaccess file to following

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} protected [NC,OR]
RewriteCond %{REQUEST_URI} protected2 [NC,OR]
RewriteCond %{REQUEST_URI} protected3 [NC]

I also forward domain to https://www.mysite.com

user1688346
  • 1,846
  • 5
  • 26
  • 48
  • Could you add the forward rule as well? – Qben Nov 01 '13 at 08:58
  • see this (it works for me) : https://stackoverflow.com/questions/31467871/setting-up-https-redirects-on-heroku-laravel-instance# – MaB May 07 '16 at 21:27

2 Answers2

0
RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context

Source

alandarev
  • 8,349
  • 2
  • 34
  • 43
  • I have pulled it out of the apache wiki, assumingly it shall work. If you have access to virtual hosts configuration, then use [this](http://wiki.apache.org/httpd/RedirectSSL) – alandarev Nov 01 '13 at 08:59
0

Using a htaccess file:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R,L]

Using PHP to direct:

  exit(header("location: https://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"));

Both should work. :-)

Corbin Spicer
  • 285
  • 1
  • 8
  • 26