Skip to content

Commit

Permalink
added better redirects where subdomains can redirect if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
shanebo committed Apr 1, 2014
1 parent b7bdf0e commit cfdfc9e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/middleware/redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ var Redirects = function(options){
Redirects.prototype = {

handler: function(request, response, next){
var protocol = request.connection.encrypted ? 'https://' : 'http://';
var host = request.headers.host ? request.headers.host.split(':')[0] : false;

if (this.redirects[request.url]) {
response.redirect(this.redirects[request.url], 301);
} else if (!host && next) {
next();
} else if (this.redirects[protocol + host]) {
response.redirect(this.redirects[protocol + host] + request.url, 301);
} else if (next) {
next();
}
Expand Down

0 comments on commit cfdfc9e

Please sign in to comment.