我已经在ubuntu (apache2服务器)上部署了vue cli项目,在vue路由器模式改变后,所有页面除了索引,在重新加载时都显示404页面。
我在index.html所在的/dist路径中添加了.htaccess,但它仍然不起作用。我不知道还能做些什么来解决这个问题。有没有人知道些什么?
这是我的项目dist文件夹
/home/admin/web/mali-nali.com/public_html/distdist中的.htaccess代码
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>这是htacccess.madewithlove.be调试信息
RewriteEngine On RewriteEngine was now turned on
2 RewriteBase / Using / as the base for the rewrites.
3 RewriteRule ^index\.html$ - [L] This rule was not met.
4 RewriteCond %{REQUEST_FILENAME} !-f This condition was met.
5 RewriteCond %{REQUEST_FILENAME} !-d This condition was met.
6 RewriteRule . /index.html [L] The new url is https://mali-nali.com/index.html
The tests are stopped because of the L in your RewriteRule options.所有不存在的页面的最后一个路由
{path: '/*',component:FourohFour, name:'404'}发布于 2019-10-19 06:47:01
来自https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations
注意:以下示例假设您从根文件夹提供应用程序。如果您部署到子文件夹,则应使用Vue CLI的*publicPath*选项以及路由器的相关*base*属性。
看起来这就是你所错过的。
发布于 2019-10-19 18:29:05
在您的Vue项目的根目录中,使用以下代码添加一个名为vue.config.js的文件。
module.exports = {
publicPath: process.env.NODE_ENV === 'production' ? '/mali-nali.com/' : '/'
}然后,仍然在Vue项目的根目录中,使用以下代码添加一个名为404.html的文件。
<!DOCTYPE html>
<html>
<head>
<script>
sessionStorage.redirect = location.href;
</script>
<meta http-equiv="refresh" content="0;URL='/mali-nali.com/'">
</head>
</html>然后将您创建的404.html文件复制到/dist文件夹中。我希望这对你有帮助。
发布于 2021-09-20 10:46:08
在vue.config.js中设置publicPath选项
module.exports = {
publicPath: process.env.NODE_ENV === "production" ? "/subfolder-name/" : "/",
};然后,在dist目录中,创建一个.htaccess,其内容如下:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subfolder-name
RewriteRule ^subfolder-name/index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subfolder-name/index.html [L]
</IfModule>https://stackoverflow.com/questions/58456544
复制相似问题