我正在尝试使用历史模式下的路线来解决重新加载问题。按照 vue 文档,我在 index.html 所在的同一文件夹中创建了一个 .htaccess 文件。路径是/var/www/example.com/sever/public。我不确定这是否意味着它位于子文件夹中,或者子文件夹是否意味着该应用程序位于“example.com/something/index.html”之类的东西下,所以我尝试了以下两种配置。
<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_rewrite.c>
RewriteEngine On
RewriteBase /server/public
RewriteRule ^server/public/index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sever/public/index.html [L]
</IfModule>
我还读到默认情况下.htaccess可以被禁用,所以我检查了apache2.conf文件并发现
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
AccessFileName .htaccess
所以它似乎已启用。
example.com.conf 看起来像这样:
<VirtualHost *: 80>
SeverName example.com
ServerAlias www.example.com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://127.0.0.1:8082/
ProxyPassReverse / http://127.0.0.1:8082
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
也许有人可以指出我做错了什么。
对我来说,FallbackResource 是关键。 我正在使用 Apache/2.4.57 (Debian)。它可能不适用于旧版本。
我通过设置 example.com.conf 来解决这个问题,如下所示:
<VirtualHost *:80>
DocumentRoot /home/workspaces/website
<Directory "/home/workspaces/website">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
FallbackResource /index.html
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>