Hello I’m looking to learn how to redirect all non-www (mysite.com ) to
https://www.mysite.com
I tried the following:
class ApplicationController < ActionController::Base
before_filter :check_uri
def check_uri
redirect_to request.protocol + “www.” + request.host_with_port +
request.request_uri if !/^www/.match(request.host) if Rails.env ==
‘production’
end
Problem with this is since the SSL cert on Heroku is for www.mysite.com ,
and not mysite.com , the browser throws the nasty SSL HTTPS invalid
warning.
Any ideas on how to redirect in a way that avoids the nasty SSL HTTPs
invalid warning?
Thanks
CuriousNewbie,
This is going to be more requests, but I think the easiest way to do
it is probably to redirect traffic from mysite.com to www.mysite.com ,
like you’re doing, and then redirect traffic from http: to https:
using something like ssl_requirement. That way, if somebody visits
http://mysite.com/ , they’ll be redirected to http://www.mysite.com/
and then redirected again to https://www.mysite.com/ .
Tilde E.
On Dec 1, 4:44pm, CuriousNewbie [email protected] wrote:
Any ideas on how to redirect in a way that avoids the nasty SSL HTTPs
invalid warning?
I have never used Heroku, but couldn’t you just use “https://” in the
redirect instead of request.protocol?
Hi,
you can try to modify the ssl_requirements the plugin to fit your need.
Warning: I was using it a couple of years ago and my suggestion may be
outdated
trigger the ssl required with ssl_required :action_name in the
controller and modify ensure_proper_protocol to add ‘www’ when
missing:
gistfile1.rb
# Copyright (c) 2005 David Heinemeier Hansson
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
This file has been truncated. show original
On Wed, Dec 1, 2010 at 1:44 PM, CuriousNewbie [email protected]
wrote:
Hello I’m looking to learn how to redirect all non-www (mysite.com ) to
https://www.mysite.com
–
Emanuele T.
On Dec 3, 1:54pm, Phillip [email protected] wrote:
This would typically be done by the server (usually Apache)
Agreed, but using Heroku means that it not an option.
This would typically be done by the server (usually Apache).
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
Please see this
Thanks and regards,
Shyam Mohan
Ruby on rails developer at CRYPSIS http://crypsis.net/ (Gurgaon)
Email : [email protected]
Mobile : +91-971-618-9650
Web : shyam.heroku.com
Is it possible to do something similar to this little gem? Maybe
implemented as Rack middleware.
require 'rack'
module Rack
module EY
module Solo
class DomainRedirect
attr_accessor :prefix
def initialize(app, &block)
@app = app
@prefix = nil
yield self if block_given?
end
def call(env)
parts = env['SERVER_NAME'].split('.')
suffix, chunk, prefix = parts.pop, parts.pop, parts.pop
if prefix == @prefix
@app.call(env)
else
This file has been truncated. show original
Thanks Shyam, I took at a look at the link but I’m not sure how that
would solve the redirect need? Still haven’t been able to figure this
one out…
Hi
Have u seen this…?
Thanks and regards,
Shyam Mohan
Ruby on rails developer at CRYPSIS http://crypsis.net/ (Gurgaon)
Email : [email protected]
Mobile : +91-971-618-9650
Web : shyam.heroku.com
Thanks Tim, I tried:
def check_uri
redirect_to “https://www.mysite.com ” + request.request_uri if !/
^www/.match(request.host) if Rails.env == ‘production’
end
No luck though, Chrome still shows the SSL error when you load
https://mysite.com
It seems to not being taking check_uri in effect early enough.
Any other approaches or ideas? Heroku wasn’t able to offer any advice
other than buying a wildcard cert $$$$