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

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

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)

})

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容