一天的美好时光!
我正在使用带有npm run generate
命令的静态生成的网站,虽然放在页面目录中的所有页面工作得很好(动态页面,所有实现的功能等),但不存在的页面只是返回默认的Web服务器错误页面。
在npm run dev
的本地计算机上,我可以强制使用Nuxt生成的'Page not found'错误,而在运行Apache的生产服务器上,我不能使用软件包提供的中间件(例如 @ nuxt / sitemap )以及任何可能触发错误的页面(40 *,5 **,3 **)都由Web服务器直接处理。
由于npm run dev
只是启动了 express 网络服务器,我想快递所实施的任何路由规则都可以在Apache .htaccess 配置中重现,我只是不知道在哪里找他们。
以下是来自Vue项目没有 Nuxt的配置,其中一切都按预期工作(重定向等)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
# Fonts
# Add correct content-type for fonts
AddType application/vnd.ms-fontobject .eot
AddType application/x-font-ttf .ttf
AddType application/x-font-opentype .otf
AddType application/font-woff .woff
AddType application/font-woff2 .woff2
AddType image/svg+xml .svg
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/x-font-opentype "access plus 1 year"
ExpiresByType application/font-woff "access plus 1 year"
ExpiresByType application/font-woff2 "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
但是,在Nuxt应用程序上运行相同的文件时,每个请求都会重定向回主页。
这是在 nuxt.config.js
中配置路由器的方式router: {
mode: 'history',
middleware: [
'i18n',
'check-auth'
]
}
因此,从我的角度来看,我已经为Web服务器提供了正确识别页面何时不存在(在应用程序内部)所需的信息,但它不是试图这样做,而只是检查文件是否存在物理上。