单页面应用在服务器端配置重定向问题

2018-07-26  本文已影响0人  涅风槃云

单页面应用在服务器端配置重定向问题

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)

})

上一篇下一篇

猜你喜欢

热点阅读