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

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

1.Apache 中配置

RewriteEngine On

RewriteBase /

RewriteRule ^index\.html$ - [L]

RewriteCond %{REQUEST_FILENAME}   !-f

RewriteCond %{REQUEST_FILENAME}  !-f

RewriteRule .  /index.html  [L]


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)

})

你可能感兴趣的:(单页面应用在服务器端配置重定向问题)