Index: openacs-4/packages/acs-tcl/tcl/request-processor-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/request-processor-procs.tcl,v diff -u -r1.118.2.40 -r1.118.2.41 --- openacs-4/packages/acs-tcl/tcl/request-processor-procs.tcl 16 Feb 2017 19:33:55 -0000 1.118.2.40 +++ openacs-4/packages/acs-tcl/tcl/request-processor-procs.tcl 15 Apr 2017 09:20:51 -0000 1.118.2.41 @@ -617,6 +617,31 @@ return filter_return } + + # + # UseCanonicalLocation is a experimental feature, not to be + # activated for the OpenACS 5.9.1 release. One can use this to + # force requests submitted to a alternate DNS entry to be + # redirected to a canonical name. For more background, see: + # https://support.google.com/webmasters/answer/139066?hl=en + # https://webmasters.stackexchange.com/questions/44830/should-i-redirect-the-site-ip-address-to-the-domain-name + # + if {[parameter::get -package_id [ad_acs_kernel_id] -parameter UseCanonicalLocation -default 0]} { + set canonical_location [parameter::get -package_id [ad_acs_kernel_id] -parameter SystemURL] + set current_location [util_current_location] + # + # It might be useful in the future to define per-subsite + # CanonicalLocations, and/or combine this with the host-node-map + # + if {[string index $canonical_location end] eq "/"} { + set canonical_location [string trimright $canonical_location /] + } + if {$current_location ne $canonical_location} { + ns_returnmoved $canonical_location$ad_conn_url + return filter_return + } + } + # 2. handle special case: if the root is a prefix of the URL, # remove this prefix from the URL, and redirect. if { $root ne "" } { @@ -627,10 +652,10 @@ } if { [security::secure_conn_p] } { # it's a secure connection. - ad_returnredirect -allow_complete_url https://[ad_host][ad_port]$url + ns_returnmoved https://[ad_host][ad_port]$url return filter_return } else { - ad_returnredirect -allow_complete_url http://[ad_host][ad_port]$url + ns_returnmoved http://[ad_host][ad_port]$url return filter_return } }