首页 > 解决方案 > 简单的 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 不安全。

有什么理由吗?

标签: .htaccessmod-rewriteurl-rewriting

解决方案


这样做解决了问题:

# 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]

不幸的是,它作为缓存清除方法没有成功,但无论如何这不是这个问题的重点。


推荐阅读