1.vue router 使用 History 模式后端 apa

2019-07-18  本文已影响0人  天听云道

1.Vue router 使用history模式,URL会比hash模式好看,但是需要后端的配合,不然会报以下错误

The requested URL /* was not found on this server

2.web服务器是Apache的相关配置

1.在上传的web项目根目录下创建 .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>

2.设置apache支持mod_rewrite

找到apache安装目录 etc/apache/conf/ 下的 httpd.conf 文件
通过Ctrl+F查找到 LoadModule rewrite_module,将前面的”#”号删除即可。

3.设置apache支持override

在 httpd.conf 文件里
通过Ctrl+F找到对应的DocumentRoot 里的“AllowOverride None”,修改为"AllowOverride All"

4.重启apache

sudo apachectl restart

上一篇 下一篇

猜你喜欢

热点阅读