https重定向和客户端路由的.htaccess配置

时间:2018-04-24 07:39:34

标签: apache vuejs2 vue-router

我有Apache 2.4.27和两个问题:

1。重定向http - > HTTPS

2。没有#

的SPA(Vue2)客户端路由

解决 1 (可行):

RewriteEngine on
RewriteCond %{HTTP_HOST} ^site\.com [NC]
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

解决 2 (Vue官方推荐):

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

如何满足这两个条件?

1 个答案:

答案 0 :(得分:1)

RewriteEngine on

RewriteBase /

RewriteCond %{HTTP_HOST} ^yoursite\.domen [NC]
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST} [R=301,L]

RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

简单:solution1 + solution2 =它可以工作