diff --git a/lib/middleware/redirects.js b/lib/middleware/redirects.js index 1a242d53..2bfa676e 100644 --- a/lib/middleware/redirects.js +++ b/lib/middleware/redirects.js @@ -11,7 +11,6 @@ var _ = require('lodash'); var minimatch = require('minimatch'); var pathToRegexp = require('path-to-regexp'); -var slasher = require('glob-slasher'); function formatExternalUrl(u) { var cleaned = u @@ -32,10 +31,22 @@ function addQuery(url, qs) { var Redirect = function(source, destination, type) { this.type = type || 301; - this.source = slasher(source); + + // no leading slash + if (source[0] !== '/') { + // glob pattern but no leading slash + if (source[0] === '!' && source[1] && source[1] !== '/') { + this.source = '!/' + source.substring(2); + } else { + this.source = '/' + source; + } + } else { + this.source = source; + } + this.destination = destination; - if (this.destination.match(/(?:^|\/):/)) { + if (this.source.match(/(?:^|\/):/)) { this.captureKeys = []; this.capture = pathToRegexp(this.source, this.captureKeys); this.compileDestination = pathToRegexp.compile(this.destination); @@ -51,9 +62,11 @@ Redirect.prototype.test = function(url) { } var match; + if (this.capture) { match = this.capture.exec(url); } + if (match) { var params = {}; for (var i = 0; i < this.captureKeys.length; i++) {