编辑.htaccess后Vuejs App仍然会显示404页面

问题描述

我在digitalocean的apache2服务器上部署了一个Vuejs应用程序,当您点击url时,它会将您转发到登录页面,该页面运行正常,然后当我单击其中一张卡时,自动将我导航到具有卡的仪表板页面即使我在dist中编辑.htaccess文件后,还是404页面

注意,卡片路径为domain.com/build

我尝试了来自文档的.htaccess配置

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

这是我的虚拟主机配置

<IfModule mod_ssl.c>
<VirtualHost *:443>

        ServerAdmin email
        ServerName domain.com
        ServerAlias www.domain.com
        DocumentRoot /var/www/domain.com/public_html/app/dist
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        ProxyPass /api/  http://localhost:8000/
        ProxyPassReverse /api/ http://localhost:8000/
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,# because they have the potential to create redirection loops.

#RewriteCond %{SERVER_NAME} =domain.com
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

解决方法

虚拟主机文件没有问题,问题出在apache2.conf中的/etc/apache2文件中。我需要的是将这部分更改为

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

至:

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

您需要更改AllowOverride属性。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...