Routing all traffic through index.html except 'api'

191 views Asked by At

Working on a BackBone app that has this mod_rewrite in place to handle routing all traffic through index.html that isn't targeting a file:

modRewrite(['^[^\\.]*$ /index.html [L]'])

It's working beautifully, but now I need to update it so that it ignores that root-level api directory. My API calls look like this:

http://localhost:9000/api/customers/

They're all breaking because it's trying to route them through index.html. FYI, I'm using Grunt connect-modrewrite locally to manage issues with routing and localhost.

1

There are 1 answers

2
anubhava On BEST ANSWER

You can try negative lookahead based regex:

modRewrite(['^(?!/?api)[^\\.]*$ /index.html [L]'])