2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/vhost/application_controller_extensions.rb', line 2
def self.included(base)
base.class_eval {
prepend_before_filter :redirect_to_primary_site
helper_method :primary_site_url
def redirect_to_primary_site
if VhostExtension.REDIRECT_TO_PRIMARY_SITE
site = current_site
return if site.nil? || site.hostname.include?("*")
primary_host = site.hostnames.first.domain
redirect_to(primary_site_url + request.request_uri) if request.host != primary_host
end
end
def primary_site_url
site = current_site
return nil if site.nil? || site.hostnames.map(&:domain).include?("*")
prefix = request.ssl? ? "https://" : "http://"
host = request.host
port = request.port_string
primary_host = site.hostnames.first.domain
prefix+primary_host+port
end
}
end
|