一天中的美好时光!

我正在使用静态生成的网站 npm run generate 命令,虽然放在页面目录中的所有页面工作得很好(动态页面,所有实现的功能等),但不存在的页面只返回默认的Web服务器错误页面 .

在具有 npm run dev 的本地机器上,我可以强制使用Nuxt生成的 'Page not found' 错误,而在运行Apache的 生产环境 服务器上,我不能使用包提供的中间件(例如@ nuxt / sitemap)以及任何可能触发错误的页面(40 *,5 **,3 **)由Web服务器直接处理 .

由于 npm run dev 只是启动了 express 网络服务器,我想快递所实现的任何路由规则都可以在Apache .htaccess config中重现,我只是不知道在哪里寻找它们 .

这是我在Vue项目 without 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服务器提供了正确识别页面何时不存在(在应用程序内部)所需的信息,但它不是试图这样做,而是简单地检查文件是否存在物理存在 .