.htaccess - Htaccess 重定向到 https 同时有来自 vue-router 的另一个条件
问题描述
我想合并这两个服务器配置:
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
推荐阅读
- assembly - 什么会导致寄存器加载改变另一个寄存器的值?
- flutter - 需要帮助调整 Flutter AppBar 的大小以适应 4 行文本和
- java - 根据迭代次数将字符串用户输入添加到数组列表中
- php - 有没有办法保护访问者通过 Laravel Sanctum 中的浏览器直接访问 api url
- java - 从 Maven 导入 JavaFlacEncoder
- r - ggplot 错误 FUN 中的错误(X[[i]],...):找不到对象“Option_type”
- c# - 轮询异步数据的机制?
- typescript - 是否只有 lodash 可以深度复制对象?
- sql - 从另一个表中选择配置单元中具有最大日期的数据
- code-snippets - 如何在 lilypond 上制作带有箭头的交叉五线谱琶音