SpecialistOff.NET / Вопросы / Статьи / Фрагменты кода / Резюме / Метки / Помощь / Файлы
Список вопросов ПечатьМетки: vue.js spa одностраничное приложение single page application nginx apache http ошибка 404 not found
Если мы не сконфигурируем соответствующим образом сервер, то, при использовании одностраничного приложения, пользователи получат ошибку 404, если они перейдут по http://specialistoff.net/user/id напрямую.
| RemiZOffAlex Создано: 2019-02-04 13:25:05.149920 Обновлено: 2019-02-04 13:25:05.149920 |
|---|
Apache<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
Вместо Nginxlocation / {
try_files $uri $uri/ /index.html;
}
Node.jsconst 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('Невозможно открыть файл "index.htm".')
}
res.writeHead(200, {
'Content-Type': 'text/html; charset=utf-8'
})
res.end(content)
})
}).listen(httpPort, () => {
console.log('Сервер запущен на: http://localhost:%s', httpPort)
})
|