1.vue router 使用 History 模式后端 apache 服务配置

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容