.htaccess 如何总是重定向到SSL https而不使用http [已关闭]

8ulbf1ek  于 2022-11-16  发布在  其他
关注(0)|答案(1)|浏览(136)

已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题吗?**通过editing this post添加详细信息并阐明问题。

三个月前关门了。
Improve this question
我想改进方法,而不是使用HTTP
我们的方法是:

<VirtualHost *:80>
    ServerName example.com
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^example.com
    RewriteRule ^(.*)$ https://example.com/$1?referer_id=186 [QSA]
    RewriteRule ^      https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
hxzsmxv2

hxzsmxv21#

在https虚拟主机中,添加以下内容:

<VirtualHost *:443>
    [ ... the rest of the configuration ... ]

    RewriteEngine On
    RewriteCond %{QUERY_STRING} "!referer_id=186"
    RewriteRule ^/(.*)$ https://example.com/$1?referer_id=186 [R,QSA]

</VirtualHost>
  • RewriteCond:当“referer_id=186”不存在时匹配
  • RewriteRule:将“referer_id=186”添加到重定向。
  • QSA:将保留任何已存在的查询字符串参数,因此添加了186部分,但不删除其他已存在的参数。

相关问题