// module dependencies
var parsePath = require("./parsePath")
	, precompile = require("./precompile")
	, compile = require("./compile")
	, sanitize = require("sanitize-arguments");

// expose redirect plugin
module.exports = plugin;

// mount the redirect method
function plugin(app) {
	app.redirect = redirect;
	return app;
}

// app.redirect(route, target, status)
function redirect(route, target, status, method, check) {
	var args = sanitize(arguments, redirect, [[String, RegExp], ["/"], [302], ["all"], [Function, false]])
		, status = args.status
		, method = args.method.toLowerCase()
		, target = precompile(parsePath(args.route), parsePath(args.target))
		, check = args.check;
	
	// register route
	if(!check) {
		this[method](route, function(req, res, next) {
			var compiled = compile(req.params, target);
			
			if(compiled != req.url) res.redirect(status, compiled);
			else next();
		});
	} else {
		this[method](route, function(req, res, next) {
			var compiled = compile(req.params, target)
				, result = check(route, compiled, req, res);
			
			if(result === false) return next();
			else if(typeof result == "string") res.redirect(status, result);
			else if(compiled != req.url) res.redirect(status, compiled);
			else next();
		});
	}

	// chaining
	return this;
}

@@ -840,24 +840,317 @@
 get);%0D%0A%09%09%09%0D%0A
+%09%09%09//Make sure querystring is appended%0D%0A%09%09%09var querystring = %5B%5D;%0D%0A%09%09%09var i;%0D%0A%09%09%09for (i in req.query) %7B%0D%0A%09%09%09%09querystring.push(encodeURIComponent(i) + %22=%22 + encodeURIComponent(req.query%5Bi%5D));%0D%0A%09%09%09%7D%0D%0A%09%09%09%0D%0A%09%09%09if (querystring.length %3E 0) %7B%0D%0A%09%09%09%09compiled += %22?%22 + querystring.join(%22&%22);%0D%0A%09%09%09%7D%0D%0A%09%09%09%0D%0A
 %09%09%09if(compil

Make sure querystring is appended to redirects