我想合并这两个服务器配置:
1) Vue-router docs (正确显示路径)
<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)我也想重定向用户使用https://
,我在网上找到了解决方案:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
如何连接这两者以便我可以在我的 .htaccess
文件中使用它们?
最佳答案
您可以使用以下规则:
<IfModule mod_rewrite.c>
RewriteEngine on
#enforce https
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
#rewrite non-existent uris to /index.html
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
如果您希望永久重定向(浏览器和搜索引擎缓存),请在 http 到 https 规则中将 R
更改为 R=301
。
关于.htaccess - Htaccess 重定向到 https,同时有来自 vue-router 的另一个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55549337/