With this being a fairly dated post, I thought I'd share what I had to do since some of the libraries are out of date with even the libraries referenced. Also this shows the entire process, rather than piecemealing the comments.
The example in the library https://github.com/viart/grunt-connect-rewrite is using a very dated version of grunt-contrib-connect
From version 0.11.x, the new grunt-contrib-connect does not support connect.static and connect.directory. You need to use another library serve-static
var rewriteRulesSnippet = require('grunt-connect-rewrite/lib/utils').rewriteRequest,
serveStatic = require('serve-static');
connect: {
options: {
port: 9000,
hostname: 'localhost',
livereload: true //default port is 35729
},
rules: [
{ from: '^/yourfolder/(.*)$', to: '/$1' }
],
server: {
options: {
base: './app', //where the files are served from
open: {
target: 'http://localhost:9000/yourfolder'
},
middleware: function(connect, options) {
return [
rewriteRulesSnippet, // RewriteRules support
serveStatic(options.base[0]) // new library used here
];
}
}
}
}