0
我正在尋找一種方法來設置動態URL http://host.com/dynamic_value-123/,並能夠獲取這些值(123)Node.js的htaccess的像得到規則
我正在尋找一種方法來設置動態URL http://host.com/dynamic_value-123/,並能夠獲取這些值(123)Node.js的htaccess的像得到規則
考慮你有Node.js的服務器的最基本的例子,你可以通過req.url.split('-')[1]
實現:
var http = require('http');
http.createServer(function (req, res) {
console.log(req.url.split('-')[1]);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8080);
console.log('Server running at http://127.0.0.1:8080/');
你是什麼意思的'設置動態網址'? – alessioalex 2011-12-19 13:16:47
所有獲得('/*.*')將在我的情況下做到這一點,但我想我不能設置「*。*」 – Radoslav 2011-12-19 13:24:12