vue-cli 打包 使用 history模式 的後端配置

暮木_發表於2018-01-08

apache的配置

這是windows下的

在httpd-vhosts.conf檔案中把目錄指向專案index.html檔案所在的位置

# Virtual Hosts
#
<VirtualHost *:80>
ServerName localhost
DocumentRoot D:/wamp64/www/huanzuan/dist
<Directory  "D:/wamp64/www/huanzuan/dist">
Options Indexes FollowSymLinks
          AllowOverride All    
          Order allow,deny
          Allow from all
</Directory>
</VirtualHost>

然後再 index.html檔案的同級路徑下 建立.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>

內容就是官方文件給的 一點都不用改

然後確保 config/index.js中的build下的

assetsPublicPath: `/`,

是絕對路徑就可以了

相關文章