Is it possible to build a code like this in node.js
?
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond% {REQUEST_URI}! / (View) / [NC]
RewriteCond% {REQUEST_FILENAME}!-F
RewriteRule ^ (. *) $ Index.html [L, QSA]
</IfModule>
url display a route is not "view" and also the file does not exist then write index.html
.
using something like express
or connect
UPDATE: I need a regular expression for !/(view)/
in route for express
in node.js
.
Have you tried:
Catch everything else
app.configure(function(){
app.use(express.static(__dirname+'/public')); // Catch static files
app.use(app.routes);
});
// Catch /view and do whatever you like
app.all('/view', function(req, res) {
});
// Catch everything else and redirect to /index.html
// Of course you could send the file's content with fs.readFile to avoid
// using redirects
app.all('*', function(req, res) {
res.redirect('/index.html');
});
OR
Check if URL is /view
app.configure(function(){
app.use(express.static(__dirname+'/public')); // Catch static files
app.use(function(req, res, next) {
if (req.url == '/view') {
next();
} else {
res.redirect('/index.html');
}
});
});
OR
Catch NOT /view
app.configure(function(){
app.use(express.static(__dirname+'/public')); // Catch static files
app.use(app.routes);
});
app.get(/^(?!\/view$).*$/, function(req, res) {
res.redirect('/index.html');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With