.htaccess - 简单的 301 重定向后 HTTPS 神秘丢失
问题描述
我有以下 .htaccess
# force https and wwww ( works as expected )
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
# force cache busting via incrementable value (00x)
RewriteRule ^launch-test/?$ /launch-test-004/ [NC,R=301,L]
# call the appropriate script
RewriteRule ^launch-test-004/?$ /wid-test/php/start.php [NC]
我面临的问题是第二条规则(用于缓存破坏的规则)将 HTTPS 恢复为 HTTP,这使得 url 不安全。
有什么理由吗?
解决方案
这样做解决了问题:
# force https and wwww ( works as expected )
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
# force cache busting via incrementable value (00x)
RewriteRule ^launch-test/?$ https://%{HTTP_HOST}/launch-test-004/ [R=301]
# call the appropriate script
RewriteRule ^launch-test-004/?$ /wid-test/php/start.php [NC]
不幸的是,它作为缓存清除方法没有成功,但无论如何这不是这个问题的重点。
推荐阅读
- c# - 如何检查 int 是否在列表中出现 3 次?
- java - 动态 JPA 查询:“找不到属性”
- c# - winform应用程序设计界面打不开
- spring-integration - 如何使用 gradlew 构建 Spring 集成示例?
- javascript - 在 JavaScript 中解密 Jwt 令牌
- c# - 我无法截屏
- python - 将pygame表面转换为图像?
- node.js - 如何使用 tf.loadLayersModel() 从 express 加载 tensorflow-js 权重?
- python - 如何分割手写数字
- css - 即使容器没有,CSS Flex 元素也会溢出页面