0
私はapache2からnodejs expressサーバーに移動中です。このプロセスでは、.htaccessをexpressjsルートに変換する必要がありますが、これを達成する方法を理解することはできません。.htaccess to expresssルート
ここで.htaccessファイルです:
RewriteEngine On
#Remove .html from urls
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
# Is it a file? serve it, is it not a file? serve index.html
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]
だから基本的には、それがブラウザにすべてのファイルを提供しています。また、要求されたパスがファイルでない場合は、index.htmlを提供します。 expressjsルートでは、これらはどのように見えますか?
は現在、ルートはデフォルトの設定でexpressjs static methodを使用している場合は、このルールがすでに適用されているので、あなたが何かを追加する必要はありません。この
var express = require('express');
var app = express();
var path = require('path');
app.use(express.static("public"));
app.get('*', function (req, res) {
res.sendFile('index.html',{root: path.join(__dirname, './public')});
});
app.listen(80, function() {
console.log('Example app listening on port 3000!');
});
私はindex.htmlにする必要がありますルートは、仕事を得ることができますが、私はそれが存在する場合は、 'ex.html'にサービスを提供することになっている' localhost /をex'、のようなSTHをロードしない場合。 –
一方、私はfs.access文を書くことができます... –
更新された答えを参照 – yeiniel