單頁(yè)面應(yīng)用在服務(wù)器端配置重定向問(wèn)題
1.Apache 中配置
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME}? ?!-f
RewriteCond %{REQUEST_FILENAME}? !-f
RewriteRule .? /index.html? [L]
</IfModule>
2. Nginx
location / {
try_files $uri? $uri/? /index.html;
}
3.??原生Node.js
const http = require('http')
const fs = require('fs')
const httpPort = 80
http.createServer((req, res) => {?
?fs.readFile('index.htm','utf-8', (err, content) => {????if(err) {
console.log('We cannot open 'index.htm' file.')
?}
?res.writeHead(200, {
'Content-Type':'text/html; charset=utf-8'
})
?res.end(content) })}).listen(httpPort, () => {
console.log('Server listening on: http://localhost:%s', httpPort)
})