vue2多页面开发 - 部署Apache服务器 - 404报错

115 阅读1分钟

项目是用的多页面开发,项目在打包后会有多个html文件,这里会和单页面不太一样

这个是多页面打包后的目录结构

image.png

项目在上传到服务器后,网站目录绑定到html页面这一目录下。

路由使用的是history模式,我的首页是pc.html

【重要】Apache配置

    <Directory "/www/wwwroot/********/">
        SetOutputFilter DEFLATE
        Options FollowSymLinks
        AllowOverride All
        Require all granted
        DirectoryIndex pc.html index.php index.html index.htm default.php default.html default.htm
        RewriteEngine On
        RewriteBase /  

        RewriteRule ^pc$ pc.html [L]
        RewriteRule ^detail$ detail.html [L]
        RewriteRule ^list$ list.html [L]
        
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /pc.html [L]
    </Directory>

在这里对pc,detail,list进行重定向,让他们对到对应的html文件就好了。 如果不进行重定向就会显示404报错