这个的.htaccess的nodejs相当于 [英] nodejs equivalent of this .htaccess

查看:268
本文介绍了这个的.htaccess的nodejs相当于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能建立一个code这样的的node.js

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>

网址显示的路线是不是视图,也该文件不存在,则写 index.html的

使用类似 EX preSS 连接

更新:我需要一个正规的前pression为 /(视图)/ 的路线 EX preSS 的node.js

UPDATE: I need a regular expression for !/(view)/ in route for express in node.js.

推荐答案

您是否尝试过:

  1. 即成静
  2. 在捕捉/浏览网址
  3. 抓住一切

  1. Serve statics
  2. Catch /view URL
  3. 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'); 
});

  1. 即成静
  2. 检查URL是/视图

  1. Serve statics
  2. 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');
    }
  });
});

  1. 在捕捉静态照常
  2. 勿抓/视图

  1. Catch statics as usual
  2. 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');
});

这篇关于这个的.htaccess的nodejs相当于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆